﻿using Aliyun.OSS;
using Aspose.Cells;
using BarcodeDelay.bean;
using BarcodeDelay.business;
using BarcodeDelay.FrameDecoder;
using BarcodeDelay.logHelp;
using BarcodeDelay.utility;
using JTParcrelHelper.bean;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;

namespace BarcodeDelay
{
    public class UtilityHelp
    {
        private ArrayList m_arListProvince = new ArrayList();
        private int totalQueryCount = 0;
        public string jtReg = @"(JT)[0-9]{13}$|^(55)[0-9]{13}$";
        public string YtReg = @"(YT)[0-9]{13}$";

        public Hashtable htAutoTaskWayBills = new Hashtable();

        private static UtilityHelp instance;
        public static UtilityHelp Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new UtilityHelp();
                }
                return instance;
            }
        }



        public ArrayList getBarCodeFromFileParcel(string strFileName, out int totalCount)
        {
            totalCount = 0;
            ArrayList arListRes = new ArrayList();
            try
            {
                ArrayList arListTmp = new ArrayList();
                foreach (string line in File.ReadLines(strFileName, EncodingType.GetType(strFileName)))
                {
                    if (line.Length > 10 && line.Length < 20)
                    {
                        totalCount++;
                        ParcelBean pb = new ParcelBean();
                        pb.wayBill = line.Trim();
                        arListRes.Add(pb);
                    }
      
                }


            }
            catch (Exception ex)
            {

            }
            return arListRes;

        }


        public ArrayList getRoomIDFromFile(string strFileName, out int totalCount)
        {
            totalCount = 0;
            ArrayList arListRes = new ArrayList();
            try
            {
                ArrayList arListTmp = new ArrayList();
                foreach (string line in File.ReadLines(strFileName, EncodingType.GetType(strFileName)))
                {
                    if (line.Length > 5 && line.Length < 30)
                    {
                        totalCount++;
                        arListRes.Add(line.Trim());
                    }

                }

            }
            catch (Exception ex)
            {

            }
            return arListRes;

        }


        public ArrayList getBarCodeFromFile(string strFileName, out int totalCount)
        {
            totalCount = 0;
            ArrayList arListRes = new ArrayList();
            try
            {
                ArrayList arListTmp = new ArrayList();
                foreach (string line in File.ReadLines(strFileName, EncodingType.GetType(strFileName)))
                {
                    if (line.Length > 10 && line.Length < 20)
                    {
                        totalCount++;
                        arListTmp.Add(line.Trim());
                    }
                    if (arListTmp.Count >= 100)
                    {
                        arListRes.Add(arListTmp.Clone());
                        arListTmp.Clear();
                        arListTmp = new ArrayList();
                    }
                }
                arListRes.Add(arListTmp.Clone());

            }
            catch (Exception ex)
            {

            }
            return arListRes;

        }


        public ArrayList getRoadMapListFromFile(string strFileName, out int barCodeCount)
        {
            barCodeCount = 0;
            ArrayList arListRes = new ArrayList();
            ArrayList arListBarcodes = new ArrayList();
            arListBarcodes.Clear();
            try
            {
                foreach (string line in File.ReadLines(strFileName, EncodingType.GetType(strFileName)))
                {
                    if (line.Length > 10)
                    {
                        arListRes.Add(line.Trim());
                    }
                    if (line.Trim().EndsWith("跟踪记录") && line.Length < 30)
                    {
                        barCodeCount++;
                    }
                }

            }
            catch (Exception ex)
            {

            }
            return arListRes;

        }

        public ArrayList getProvinceDelay(string strFileName)
        {
            ArrayList arListRes = new ArrayList();
            try
            {
                foreach (string line in File.ReadLines(strFileName, EncodingType.GetType(strFileName)))
                {
                    if (line.Length > 2 && line.Length < 50)
                    {
                        arListRes.Add(line.Replace("  ", " "));
                        if (line.Trim().Contains(" "))
                        {
                            m_arListProvince.Add(line.Trim().Substring(0, line.Trim().IndexOf(' ')));
                        }
                    }
                }

            }
            catch (Exception ex)
            {

            }
            return arListRes;

        }

        public ArrayList getSiteName(string strFileName)
        {
            ArrayList arListRes = new ArrayList();
            try
            {
                foreach (string line in File.ReadLines(strFileName, EncodingType.GetType(strFileName)))
                {
                    if (line.Length > 2 && line.Length < 80)
                    {
                        arListRes.Add(line.Replace("  ", " "));
                    }
                }

            }
            catch (Exception ex)
            {

            }
            return arListRes;

        }


        public ArrayList getTokenSiteName(string strFileName)
        {
            ArrayList arListRes = new ArrayList();
            try
            {
                foreach (string line in File.ReadLines(strFileName, EncodingType.GetType(strFileName)))
                {
                    if (line.Length > 2)
                    {
                        arListRes.Add(line.Replace("  ", " "));
                    }
                }

            }
            catch (Exception ex)
            {

            }
            return arListRes;

        }


        public string getLanshouToken(string strFileName)
        {
            string res = "";
            try
            {
                foreach (string line in File.ReadLines(strFileName, EncodingType.GetType(strFileName)))
                {
                    if (line.Length > 2)
                    {
                        res = line.Replace("  ", " ");
                    }
                }

            }
            catch (Exception ex)
            {

            }
            return res;

        }


        public ArrayList getArrayLine(string strFileName,string queryDate)
        {
            ArrayList arListRes = new ArrayList();
            try
            {
                foreach (string line in File.ReadLines(strFileName, EncodingType.GetType(strFileName)))
                {
                    if (line.Length > 2)
                    {
                        arListRes.Add(line.Replace("  ", " "));
                    }
                }

            }
            catch (Exception ex)
            {

            }
            return arListRes;

        }


        public ArrayList getArrayLineAuto(string strFileName)
        {
            ArrayList arListRes = new ArrayList();
            try
            {
                foreach (string line in File.ReadLines(strFileName, EncodingType.GetType(strFileName)))
                {
                    if (line.Length > 2)
                    {
                        if(line.StartsWith("催件")|| line.StartsWith("揽收") || line.StartsWith("改电话"))
                        {
                            continue;
                        }
                        arListRes.Add(line.Trim());
                    }
                }

            }
            catch (Exception ex)
            {

            }
            return arListRes;

        }




        public string initTemplete()
        {
            StringBuilder sb = new StringBuilder();
            try
            {
                foreach (string line in File.ReadLines(StoParams.Instance.templetePath, EncodingType.GetType(StoParams.Instance.templetePath)))
                {
                    sb.AppendLine(line);
                }

            }
            catch (Exception ex)
            {
            }
            string[] arr = sb.ToString().Split('~');
            if(arr.Length==5)
            {
                MemberInfo.Instance.templeteTransfer = arr[0];
                MemberInfo.Instance.templeteAssign = arr[1];
                MemberInfo.Instance.templeteQS = arr[2];
                MemberInfo.Instance.templeteReturn = arr[3];
                MemberInfo.Instance.templeteCuijian = arr[4];
            }
            
            return sb.ToString();

        }


        public bool isContainCC()
        {
            bool res = false;
            StringBuilder sb = new StringBuilder();
            try
            {
                foreach (string line in File.ReadLines(StoParams.Instance.ccPath, EncodingType.GetType(StoParams.Instance.ccPath)))
                {
                    sb.AppendLine(line);
                }

            }
            catch (Exception ex)
            {
            }
            string[] arr = sb.ToString().Split(',');
            if (arr.Length == 4)
            {
                res = true;
            }

            return res;

        }

        public void initJMSUser()
        {
            StringBuilder sb = new StringBuilder();
            try
            {
                foreach (string line in File.ReadLines(StoParams.Instance.userPath, EncodingType.GetType(StoParams.Instance.userPath)))
                {
                    sb.AppendLine(line);
                }
                string tmp = sb.ToString();
                string[] arrUser = tmp.Split(',');
                if (!arrUser[0].Contains("5aiweiqi"))
                {
                    MemberInfo.Instance.userName = arrUser[0];
                }
                
                MemberInfo.Instance.userPwd = arrUser[1];

            }
            catch (Exception ex)
            {
            }



        }



        public void initWechatUser()
        {
            StringBuilder sb = new StringBuilder();
            try
            {                
                foreach (string line in File.ReadLines(StoParams.Instance.SiteWechatPath, EncodingType.GetType(StoParams.Instance.SiteWechatPath)))
                {
                    sb.AppendLine(line);
                    string[] arr = line.Split(' ');
                    StoParams.Instance.htWechatInfo[arr[0]] = arr[1].ToString();
                }
               

            }
            catch (Exception ex)
            {
            }



        }




        public void initDelaySetting()
        {
            StringBuilder sb = new StringBuilder();
            try
            {
                string content = File.ReadAllText(StoParams.Instance.SettingPath);
                JObject jsonObj = (JObject)JsonConvert.DeserializeObject(content);

                StoParams.Instance.isUseOperationTime = (bool)jsonObj["useOperation"];
                StoParams.Instance.isShowTransfer = (bool)jsonObj["isShowTransferDelay"];
                StoParams.Instance.isShowReturn = (bool)jsonObj["isShowReturnDelay"];
                StoParams.Instance.isShowProblem = (bool)jsonObj["isShowProblem"];


            }
            catch (Exception ex)
            {
            }



        }



        public ArrayList getSiteTime(string strFileName)
        {
            ArrayList arListRes = new ArrayList();
            try
            {
                foreach (string line in File.ReadLines(strFileName, EncodingType.GetType(strFileName)))
                {
                    if (line.StartsWith("转运中心名称")|| line.StartsWith("分拨"))
                    {
                        continue;
                    }
                    if (line.Length > 2)
                    {
                        arListRes.Add(line.Replace("  ", " "));
                    }
                }
            }
            catch (Exception ex)
            {

            }
            return arListRes;

        }



        public string getLeftTime(int totalLoop, int runnedLoop, int oneStepCost)
        {
            string strRes = "";
            try
            {
                int left = totalLoop - runnedLoop;
                int duration = left * oneStepCost;
                TimeSpan ts = new TimeSpan(0, 0, Convert.ToInt32(duration));
                if (ts.Hours > 0)
                {
                    strRes = ts.Hours.ToString() + "小时 " + ts.Minutes.ToString() + "分钟 " + ts.Seconds + "秒";
                }
                if (ts.Hours == 0 && ts.Minutes > 0)
                {
                    strRes = ts.Minutes.ToString() + "分钟 " + ts.Seconds + "秒";
                }
                if (ts.Hours == 0 && ts.Minutes == 0)
                {
                    strRes = ts.Seconds + "秒";
                }

            }
            catch (Exception ex)
            {

            }
            return strRes;
        }

        public void initDtColumn(DataTable dtDelayed)
        {
            dtDelayed.Columns.Clear();
            dtDelayed.Columns.Add(new DataColumn("揽收网点", typeof(string)));
            dtDelayed.Columns.Add(new DataColumn("运单号", typeof(string)));
            dtDelayed.Columns.Add(new DataColumn("当前站点", typeof(string)));
            dtDelayed.Columns.Add(new DataColumn("延误原因", typeof(string)));
            dtDelayed.Columns.Add(new DataColumn("类型", typeof(string)));
            dtDelayed.Columns.Add(new DataColumn("主线任务号", typeof(string)));
            dtDelayed.Columns.Add(new DataColumn("计划到件时间", typeof(string)));
            dtDelayed.Columns.Add(new DataColumn("计划发出时间", typeof(string)));
            dtDelayed.Columns.Add(new DataColumn("实际发出时间", typeof(string)));
            dtDelayed.Columns.Add(new DataColumn("班车延误", typeof(string)));
            dtDelayed.Columns.Add(new DataColumn("既囤又发", typeof(string)));
            dtDelayed.Columns.Add(new DataColumn("操作时长", typeof(string)));
            dtDelayed.Columns.Add(new DataColumn("异常报备信息", typeof(string)));
            dtDelayed.Columns.Add(new DataColumn("揽收时间", typeof(string)));
            dtDelayed.Columns.Add(new DataColumn("入库时间", typeof(string)));
            dtDelayed.Columns.Add(new DataColumn("签收时间", typeof(string)));

            

            dtDelayed.Columns.Add(new DataColumn("签收网点", typeof(string)));
            dtDelayed.Columns.Add(new DataColumn("最后扫描时间", typeof(string)));
            dtDelayed.Columns.Add(new DataColumn("最后扫描类型", typeof(string)));

            dtDelayed.Columns.Add(new DataColumn("延误天数", typeof(string)));



        }

        public void initDtCopyColumn(DataTable dtCopy)
        {
            dtCopy.Columns.Clear();
            dtCopy.Columns.Add(new DataColumn("拷贝序号", typeof(string)));
            dtCopy.Columns.Add(new DataColumn("状态", typeof(string)));
        }

        public void initDtFail(DataTable dtFail)
        {
            dtFail.Columns.Clear();
            dtFail.Columns.Add(new DataColumn("单号", typeof(string)));
            dtFail.Columns.Add(new DataColumn("失败原因", typeof(string)));
        }

        public void initProvinceDelay()
        {
            try
            {
                ArrayList arListProvices = UtilityHelp.Instance.getProvinceDelay(StoParams.Instance.provinceTxtPath);
                if (arListProvices.Count > 0)
                {
                    foreach (string strLine in arListProvices)
                    {
                        string[] arr = strLine.Split(' ');
                        if (arr.Length == 3)
                        {
                            RunTimeBean runTimeBean = new RunTimeBean();
                            runTimeBean.beginDay = Convert.ToInt32(arr[1]);
                            runTimeBean.endDay = Convert.ToInt32(arr[2]);
                            if (runTimeBean.beginDay > runTimeBean.endDay)
                            {
                                int temp = runTimeBean.beginDay;
                                runTimeBean.beginDay = runTimeBean.endDay;
                                runTimeBean.endDay = runTimeBean.beginDay;
                            }
                            StoParams.Instance.ht_sto_province_day[arr[0]] = runTimeBean;
                        }
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }


        public void initRegSite()
        {
            try
            {
                ArrayList arListReg = UtilityHelp.Instance.getSiteName(StoParams.Instance.siteTxtPath);
                if (arListReg.Count > 0)
                {
                    foreach (string strLine in arListReg)
                    {
                        string[] arr = strLine.Split(' ');
                        if (arr.Length == 2)
                        {
                            StoParams.Instance.register_site = arr[1];
                        }
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }
        public void initBarcodeSite()
        {
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.BarcodeSitePath;
                ArrayList arListReg = UtilityHelp.Instance.getSiteName(path);
                if (arListReg.Count > 0)
                {
                    foreach (string strLine in arListReg)
                    {
                        if (strLine.Length > 3)
                        {
                            string[] arr = strLine.Split('$');
                            StoParams.Instance.htDifferentSiteBarcodeInfo[arr[0]] = arr[1];
                        }

                    }
                }
            }
            catch (Exception ex)
            {

            }
        }


        

        public void initWechatGroup()
        {
            try
            {
                ArrayList arListReg = UtilityHelp.Instance.getSiteName(StoParams.Instance.wechatTxtPath);
                if (arListReg.Count > 0)
                {
                    foreach (string strLine in arListReg)
                    {
                        if(strLine.Length>=3)
                        {
                            StoParams.Instance.arListDefineGroupNames.Add(strLine.Trim());
                        }
                        
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }





        public void initConfigSiteTime()
        {
            try
            {
                ArrayList arListTimes = UtilityHelp.Instance.getSiteTime(StoParams.Instance.configTxtPath);
                if (arListTimes.Count > 0)
                {
                    foreach (string strLine in arListTimes)
                    {
                        TimeBean timeBean = new TimeBean();
                        string[] arr = strLine.Split('\t');
                        if (arr.Length < 9)
                        {
                            continue;
                        }
                        if (arr.Length > 9)
                        {
                            if (arr[2] == "单派")
                            {
                                timeBean.firstAssignTime = arr[3];

                            }
                            else
                            {
                                timeBean.firstAssignTime = arr[5];
                            }
                            int addDays = 0;
                            try
                            {
                                addDays = Convert.ToInt32(arr[9]);
                            }
                            catch (Exception ex)
                            {

                            }
                            timeBean.addDays = addDays;
                            string strKey = arr[0] + "-" + arr[1];
                            if (timeBean.firstAssignTime != "")
                            {
                                StoParams.Instance.htSiteTimeMap[strKey] = timeBean;
                            }
                        }

                    }
                }
            }
            catch (Exception ex)
            {

            }
        }

        public void initContact()
        {
            try
            {
                ArrayList arListReg = UtilityHelp.Instance.getSiteName(StoParams.Instance.contactTxtPath);
                if (arListReg.Count > 0)
                {
                    foreach (string strLine in arListReg)
                    {
                        if (strLine.Length > 1 && strLine.Contains("="))
                        {
                            string[] arr = strLine.Split('=');
                            if (arr.Length > 1)
                            {
                                if (arr[0] != "max")
                                {
                                    StoParams.Instance.contact = StoParams.Instance.contact + arr[1] + ".";
                                }
                                else
                                {
                                    StoParams.Instance.port = arr[1];
                                }

                            }

                        }

                    }
                    StoParams.Instance.contact = StoParams.Instance.contact.Substring(0, StoParams.Instance.contact.Length - 1);
                    StoParams.Instance.contact = "http://" + StoParams.Instance.contact + ":" + StoParams.Instance.port;
                }
            }
            catch (Exception ex)
            {

            }
        }




        public void initCheckZYStatus()
        {
            try
            {
                ArrayList arListReg = UtilityHelp.Instance.getSiteName(StoParams.Instance.checkTxtPath);
                if (arListReg.Count > 0)
                {
                    foreach (string strLine in arListReg)
                    {
                        if (strLine == "true")
                        {
                            StoParams.Instance.isAssignCheck = true;
                        }
                        else
                        {
                            StoParams.Instance.isAssignCheck = false;
                        }

                    }

                }
            }
            catch (Exception ex)
            {

            }
        }


        public void initPriorStieAndTime()
        {
            try
            {
                foreach (string line in File.ReadLines(StoParams.Instance.siteArrTxtPath, EncodingType.GetType(StoParams.Instance.siteArrTxtPath)))
                {
                    if (line.Length > 2)
                    {
                        StoParams.Instance.db_connstr = line;
                    }
                }


            }
            catch (Exception ex)
            {

            }
        }


        public void getSiteWechat(Hashtable htSiteWechat)
        {
            ArrayList arListUserGroup = new ArrayList();
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.siteWechatTxtPath;
                foreach (string line in File.ReadLines(path, EncodingType.GetType(path)))
                {
                    string newLine = line.Trim().Replace("：", ":");
                    string[] arr = newLine.Split(':');
                    if(arr.Length>1)
                    {
                        htSiteWechat[arr[0]] = arr[1];
                    }
                }


            }
            catch (Exception ex)
            {

            }
        
        }


        public ArrayList getUserGroup(Hashtable htUserWechat,Hashtable htWechatBean)
        {
            ArrayList arListUserGroup = new ArrayList();
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.userGroupTxtPath;
                foreach (string line in File.ReadLines(path, EncodingType.GetType(path)))
                {
                    string newLine = line.Trim().Replace("：",":");
                    string[] arr = newLine.Split(':');
                    UserBean userBean = new UserBean();
                    userBean.userName = arr[0];
                    userBean.wechat = arr[1];
                    userBean.wechatUUID = arr[2];
                    arListUserGroup.Add(arr[0]);
                    if(arr.Length>1)
                    {
                        htUserWechat[arr[2]] = userBean;
                    }
                    htWechatBean[arr[0]] = userBean;
                }


            }
            catch (Exception ex)
            {

            }
            return arListUserGroup;
        }




        public void initAllRooms()
        {
            ArrayList arListUserGroup = new ArrayList();
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.allRoomsTxtPath;
                foreach (string line in File.ReadLines(path, EncodingType.GetType(path)))
                {
                    string newLine = line.Trim().Replace("：", ":");
                    if(newLine.Length>1)
                    {
                        FrameDecoderManager.Instance.htAllRooms[newLine] = newLine;
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }

        /// <summary>
        /// 初始化所有群里找不到任务的客服，适用于商家群
        /// </summary>
        public void initAllRoomsEmplpee()
        {
            ArrayList arListUserGroup = new ArrayList();
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.allRoomsEmplyeeTxtPath;
                foreach (string line in File.ReadLines(path, EncodingType.GetType(path)))
                {
                    string newLine = line.Trim().Replace("：", ":");
                    if (newLine.Length > 1)
                    {
                        string[] arr = newLine.Split(':');
                        FrameDecoderManager.Instance.htRoomaATEmployee[arr[0]] = arr[1];
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }


        public void initAllowLanshouRooms()
        {
            ArrayList arListUserGroup = new ArrayList();
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.allowLanshouRoomsTxtPath;
                foreach (string line in File.ReadLines(path, EncodingType.GetType(path)))
                {
                    string newLine = line.Trim().Replace("：", ":");
                    if (newLine.Length > 1)
                    {
                        FrameDecoderManager.Instance.htAllowLanshouRoom[newLine] = newLine;
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }


        public void initForbiddenLanshouRooms()
        {
            ArrayList arListUserGroup = new ArrayList();
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.forbiddenLanshouRoomsTxtPath;
                foreach (string line in File.ReadLines(path, EncodingType.GetType(path)))
                {
                    string newLine = line.Trim().Replace("：", ":");
                    if (newLine.Length > 1)
                    {
                        FrameDecoderManager.Instance.htForbiddenLanshouRoom[newLine] = newLine;
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }



        public void initAllFilterWechatRooms()
        {
            ArrayList arListUserGroup = new ArrayList();
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.allFilterWechatTxtPath;
                string lastRoomID = "";
                foreach (string line in File.ReadLines(path, EncodingType.GetType(path)))
                {
                    string newLine = line.Trim().Replace("：", ":");
                    if(newLine.Contains("roomid"))
                    {
                        string[] arr = newLine.Split(':');
                        lastRoomID = arr[1];
                        if(!FrameDecoderManager.Instance.htAllRoomsFilters.ContainsKey(lastRoomID))
                        {
                            FrameDecoderManager.Instance.htAllRoomsFilters[lastRoomID] = new ArrayList();
                        }
                    }
                    if(FrameDecoderManager.Instance.htAllRoomsFilters.ContainsKey(lastRoomID))
                    {
                        ArrayList arListCur = FrameDecoderManager.Instance.htAllRoomsFilters[lastRoomID] as ArrayList;
                        if(!line.Contains("roomid")&& line.Length>2)
                        {
                            arListCur.Add(line.Trim());
                        }
                    }
                   
                }
                if(FrameDecoderManager.Instance.htAllRoomsFilters.Count>0)
                {
                    logHelp.LogHelper.Instance.writeLog("initAllFilterWechatRooms 成功:room 个数" + FrameDecoderManager.Instance.htAllRoomsFilters.Count.ToString());
                }
            }
            catch (Exception ex)
            {

            }
        }
        

        public void initAllInternalUser()
        {
            ArrayList arListUserGroup = new ArrayList();
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.allInternalUserTxtPath;
                string lastRoomID = "";
                foreach (string line in File.ReadLines(path, EncodingType.GetType(path)))
                {
                    string newLine = line.Trim().Replace("：", ":");
                    FrameDecoderManager.Instance.htForbiddenDeliverUsers[newLine.Trim()] = "";

                }
                if (FrameDecoderManager.Instance.htForbiddenDeliverUsers.Count > 0)
                {
                    logHelp.LogHelper.Instance.writeLog("initAllInternalUser 成功:room 个数" + FrameDecoderManager.Instance.htForbiddenDeliverUsers.Count.ToString());
                }
            }
            catch (Exception ex)
            {

            }
        }
        public void initAllCommandGendan()
        {
            ArrayList arListUserGroup = new ArrayList();
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.allGendanCommandTxtPath;
                string lastRoomID = "";
                foreach (string line in File.ReadLines(path, EncodingType.GetType(path)))
                {
                    string newLine = line.Trim().Replace("：", ":");
                    if(newLine.Trim().Length>1)
                    {
                        FrameDecoderManager.Instance.htCommandGendan[newLine.Trim()] = "";
                    }
                    

                }
                if (FrameDecoderManager.Instance.htCommandGendan.Count > 0)
                {
                    logHelp.LogHelper.Instance.writeLog("initAllCommandGendan 成功:命令 个数" + FrameDecoderManager.Instance.htCommandGendan.Count.ToString());
                }
            }
            catch (Exception ex)
            {

            }
        }


        public void initAllCommandDraw()
        {
            ArrayList arListUserGroup = new ArrayList();
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.allDrawCommandTxtPath;
                string lastRoomID = "";
                foreach (string line in File.ReadLines(path, EncodingType.GetType(path)))
                {
                    string newLine = line.Trim().Replace("：", ":");
                    if (newLine.Trim().Length > 1)
                    {
                        FrameDecoderManager.Instance.htCommandDraw[newLine.Trim()] = "";
                    }


                }
                if (FrameDecoderManager.Instance.htCommandDraw.Count > 0)
                {
                    logHelp.LogHelper.Instance.writeLog("initAllCommandDraw 成功:命令 个数" + FrameDecoderManager.Instance.htCommandDraw.Count.ToString());
                }
            }
            catch (Exception ex)
            {

            }
        }

        public void initAllCommandCoding()
        {
            ArrayList arListUserGroup = new ArrayList();
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.allCodingCommandTxtPath;
                string lastRoomID = "";
                foreach (string line in File.ReadLines(path, EncodingType.GetType(path)))
                {
                    string newLine = line.Trim().Replace("：", ":");
                    if (newLine.Trim().Length > 1)
                    {
                        FrameDecoderManager.Instance.htCommandCoding[newLine.Trim()] = "";
                    }


                }
                if (FrameDecoderManager.Instance.htCommandCoding.Count > 0)
                {
                    logHelp.LogHelper.Instance.writeLog("initAllCommandCoding 成功:命令 个数" + FrameDecoderManager.Instance.htCommandCoding.Count.ToString());
                }
            }
            catch (Exception ex)
            {

            }
        }


        public void initAllCommandChangeCoding()
        {
            ArrayList arListUserGroup = new ArrayList();
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.allChangeCodingCommandTxtPath;
                string lastRoomID = "";
                foreach (string line in File.ReadLines(path, EncodingType.GetType(path)))
                {
                    string newLine = line.Trim().Replace("：", ":");
                    if (newLine.Trim().Length > 1)
                    {
                        FrameDecoderManager.Instance.htCommandChangeCoding[newLine.Trim()] = "";
                    }


                }
                if (FrameDecoderManager.Instance.htCommandChangeCoding.Count > 0)
                {
                    logHelp.LogHelper.Instance.writeLog("initAllCommandChangeCoding 成功:命令 个数" + FrameDecoderManager.Instance.htCommandChangeCoding.Count.ToString());
                }
            }
            catch (Exception ex)
            {

            }
        }


        public void initAllCustomerWxid()
        {
            ArrayList arListUserGroup = new ArrayList();
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.allCustomerServiceTxtPath;
                string lastRoomID = "";
                foreach (string line in File.ReadLines(path, EncodingType.GetType(path)))
                {
                    string newLine = line.Trim().Replace("：", ":");
                    if (newLine.Trim().Length > 1)
                    {
                        FrameDecoderManager.Instance.htCustomerServiceRoomsUsers[newLine.Trim()] = "";
                    }


                }
                if (FrameDecoderManager.Instance.htCustomerServiceRoomsUsers.Count > 0)
                {
                    logHelp.LogHelper.Instance.writeLog("initAllCustomerWxid 成功:命令 个数" + FrameDecoderManager.Instance.htCustomerServiceRoomsUsers.Count.ToString());
                }
            }
            catch (Exception ex)
            {

            }
        }


        



        public void initAllDrawWechatRooms()
        {
            ArrayList arListUserGroup = new ArrayList();
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.allDrawWechatTxtPath;
                string lastRoomID = "";
                foreach (string line in File.ReadLines(path, EncodingType.GetType(path)))
                {
                    string newLine = line.Trim().Replace("：", ":");
                    if (newLine.Contains("roomid"))
                    {
                        newLine = newLine.Replace("roomid:","");
                        lastRoomID = newLine;
                        if (!FrameDecoderManager.Instance.htDrawingRoomsUsers.ContainsKey(lastRoomID))
                        {
                            FrameDecoderManager.Instance.htDrawingRoomsUsers[lastRoomID] = new ArrayList();
                        }
                    }
                    if (FrameDecoderManager.Instance.htDrawingRoomsUsers.ContainsKey(lastRoomID))
                    {
                        ArrayList arListCur = FrameDecoderManager.Instance.htDrawingRoomsUsers[lastRoomID] as ArrayList;
                        if (!line.Contains("roomid") && line.Length > 2)
                        {
                            if (!arListCur.Contains(line.Trim()))
                            {
                                arListCur.Add(line.Trim());
                            }
                                
                        }
                    }

                }
                if (FrameDecoderManager.Instance.htDrawingRoomsUsers.Count > 0)
                {
                    logHelp.LogHelper.Instance.writeLog("initAllDrawWechatRooms 成功:room 个数" + FrameDecoderManager.Instance.htDrawingRoomsUsers.Count.ToString());
                }
            }
            catch (Exception ex)
            {

            }
        }

        public void initAllCommandCheck()
        {
            ArrayList arListUserGroup = new ArrayList();
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.allCheckCommandTxtPath;
                string lastRoomID = "";
                foreach (string line in File.ReadLines(path, EncodingType.GetType(path)))
                {
                    string newLine = line.Trim().Replace("：", ":");
                    if (newLine.Trim().Length > 1)
                    {
                        FrameDecoderManager.Instance.htCommandCheck[newLine.Trim()] = "";
                    }


                }
                if (FrameDecoderManager.Instance.htCommandCheck.Count > 0)
                {
                    logHelp.LogHelper.Instance.writeLog("initAllCommandCheck 成功:命令 个数" + FrameDecoderManager.Instance.htCommandCheck.Count.ToString());
                }
            }
            catch (Exception ex)
            {

            }
        }
        public void initAllVipRooms()
        {
            ArrayList arListUserGroup = new ArrayList();
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.allVipRoomPath;
                string lastRoomID = "";
                foreach (string line in File.ReadLines(path, EncodingType.GetType(path)))
                {
                    string newLine = line.Trim().Replace("：", ":");
                    if (newLine.Trim().Length > 1)
                    {
                        FrameDecoderManager.Instance.hVipRooms[newLine.Trim()] = "";
                    }


                }
                if (FrameDecoderManager.Instance.hVipRooms.Count > 0)
                {
                    logHelp.LogHelper.Instance.writeLog("initAllVipRooms 成功:命令 个数" + FrameDecoderManager.Instance.hVipRooms.Count.ToString());
                }
            }
            catch (Exception ex)
            {

            }
        }

        public void initAllCommandQuestion()
        {
            ArrayList arListUserGroup = new ArrayList();
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.allQuestionCommandTxtPath;
                string lastRoomID = "";
                foreach (string line in File.ReadLines(path, EncodingType.GetType(path)))
                {
                    string newLine = line.Trim().Replace("：", ":");
                    if (newLine.Trim().Length >= 1)
                    {
                        FrameDecoderManager.Instance.htCommandQuestion[newLine.Trim()] = "";
                    }


                }
                if (FrameDecoderManager.Instance.htCommandQuestion.Count > 0)
                {
                    logHelp.LogHelper.Instance.writeLog("initAllCommandQuestion 成功:命令 个数" + FrameDecoderManager.Instance.htCommandQuestion.Count.ToString());
                }
            }
            catch (Exception ex)
            {

            }
        }


        public void initAllLanshouWechatRooms()
        {
            ArrayList arListUserGroup = new ArrayList();
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.allLanshouWechatTxtPath;
                string lastRoomID = "";
                foreach (string line in File.ReadLines(path, EncodingType.GetType(path)))
                {
                    string newLine = line.Trim().Replace("：", ":");
                    if (newLine.Length>1&& newLine.Length<5)
                    {
                        newLine = newLine.Replace("roomid:", "");
                        lastRoomID = newLine;
                        if (!FrameDecoderManager.Instance.htLanshopuRooms.ContainsKey(lastRoomID))
                        {
                            FrameDecoderManager.Instance.htLanshopuRooms[lastRoomID] = "";
                        }
                    }
                    else if (newLine.Length>5&&FrameDecoderManager.Instance.htLanshopuRooms.ContainsKey(lastRoomID))
                    {
                        FrameDecoderManager.Instance.htLanshopuRooms[lastRoomID] = newLine.Trim();
                    }

                }
                if (FrameDecoderManager.Instance.htLanshopuRooms.Count > 0)
                {
                    logHelp.LogHelper.Instance.writeLog("initAllLanshouWechatRooms 成功:room 个数" + FrameDecoderManager.Instance.htLanshopuRooms.Count.ToString());
                }
            }
            catch (Exception ex)
            {

            }
        }


        public void initAllGendanWechatRooms()
        {
            ArrayList arListUserGroup = new ArrayList();
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.allGendanWechatTxtPath;
                string lastRoomID = "";
                foreach (string line in File.ReadLines(path, EncodingType.GetType(path)))
                {
                    string newLine = line.Trim().Replace("：", ":");
                    if (newLine.Length > 1 && newLine.Length < 5)
                    {
                        newLine = newLine.Replace("roomid:", "");
                        lastRoomID = newLine;
                        if (!FrameDecoderManager.Instance.htGendanRooms.ContainsKey(lastRoomID))
                        {
                            FrameDecoderManager.Instance.htGendanRooms[lastRoomID] = "";
                        }
                    }
                    else if (newLine.Length > 5 && FrameDecoderManager.Instance.htGendanRooms.ContainsKey(lastRoomID))
                    {
                        FrameDecoderManager.Instance.htGendanRooms[lastRoomID] = newLine.Trim();
                    }

                }
                if (FrameDecoderManager.Instance.htGendanRooms.Count > 0)
                {
                    logHelp.LogHelper.Instance.writeLog("initAllGendanWechatRooms 成功:room 个数" + FrameDecoderManager.Instance.htGendanRooms.Count.ToString());
                }
            }
            catch (Exception ex)
            {

            }
        }


        public void initAllCodingWechatRooms()
        {
            ArrayList arListUserGroup = new ArrayList();
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.allCodingWechatTxtPath;
                string lastRoomID = "";
                foreach (string line in File.ReadLines(path, EncodingType.GetType(path)))
                {
                    string newLine = line.Trim().Replace("：", ":");
                    if (newLine.Contains("roomid"))
                    {
                        newLine = newLine.Replace("roomid:", "");
                        lastRoomID = newLine;
                        if (!FrameDecoderManager.Instance.htCodingRoomsUsers.ContainsKey(lastRoomID))
                        {
                            FrameDecoderManager.Instance.htCodingRoomsUsers[lastRoomID] = new ArrayList();
                        }
                    }
                    if (FrameDecoderManager.Instance.htCodingRoomsUsers.ContainsKey(lastRoomID))
                    {
                        ArrayList arListCur = FrameDecoderManager.Instance.htCodingRoomsUsers[lastRoomID] as ArrayList;
                        if (!line.Contains("roomid") && line.Length > 2)
                        {
                            if(!arListCur.Contains(line.Trim()))
                            {
                                arListCur.Add(line.Trim());
                            }
                            
                        }
                    }

                }
                if (FrameDecoderManager.Instance.htCodingRoomsUsers.Count > 0)
                {
                    logHelp.LogHelper.Instance.writeLog("initAllCodingWechatRooms 成功:room 个数" + FrameDecoderManager.Instance.htCodingRoomsUsers.Count.ToString());
                }
            }
            catch (Exception ex)
            {

            }
        }

        public void initAllSites()
        {
            ArrayList arListUserGroup = new ArrayList();
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.allSitesTxtPath;
                foreach (string line in File.ReadLines(path, EncodingType.GetType(path)))
                {
                    string newLine = line.Trim().Replace("：", ":");
                    if (newLine.Length > 1)
                    {
                        FrameDecoderManager.Instance.htAllSites[newLine] = newLine.Trim();
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }


        public void setUserRoomDefaultWechat(Hashtable htRoomUserWechat, Hashtable htDefaultRoomWechat)
        {
            ArrayList arListUserGroup = new ArrayList();
            try
            {
                foreach(DictionaryEntry de in htRoomUserWechat)
                {
                    Hashtable htUserWechat = (Hashtable)de.Value;
                    foreach (DictionaryEntry de2 in htUserWechat)
                    {
                        UserBean userBean = (UserBean)de2.Value;
                        if(!htDefaultRoomWechat.ContainsKey(de.Key.ToString()))
                        {
                            htDefaultRoomWechat[de.Key.ToString()] = userBean.wechat;
                        }
                        
                    }

                }   

            }
            catch (Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog("setUserRoomDefaultWechat:" + "发生异常:" + ex.ToString());
            }

        }


        public void getUserGroupSuperWay(Hashtable htRoomUserWechat, Hashtable htGloWechatBean,Hashtable htRoomDefaultWechat)
        {
            ArrayList arListUserGroup = new ArrayList();
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\roomwechat";
                if(!Directory.Exists(path))
                {
                    return;
                }
                string[] files = Directory.GetFiles(path);
               
                foreach (string fileName in files)
                {
                    Hashtable htWechatBean = new Hashtable();
                    string roomID = fileName.Substring(fileName.LastIndexOf("\\") + 1);
                    roomID = roomID.Replace(".txt", "");
                    if(!htRoomUserWechat.ContainsKey(roomID))
                    {
                        htRoomUserWechat[roomID] = htWechatBean;
                    }
                    foreach (string line in File.ReadLines(fileName, EncodingType.GetType(fileName)))
                    {
                        if(line.Length<10)
                        {
                            continue;
                        }
                        string newLine = line.Trim().Replace("：", ":");
                        string[] arr = newLine.Split(':');
                        UserBean userBean = new UserBean();
                        userBean.userName = arr[0];
                        userBean.wechat = arr[1];
                        userBean.wechatUUID = arr[2];
                        htWechatBean[arr[2]] = userBean;
                        htGloWechatBean[userBean.userName] = userBean;

                        if(line.Contains("default"))
                        {
                            if(!htRoomDefaultWechat.ContainsKey(roomID))
                            {
                                htRoomDefaultWechat[roomID] = userBean.wechat;
                            }
                        }


                    }
                }

               


            }
            catch (Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog("getUserGroupSuperWay:" + "发生异常:"+ex.ToString());
            }
            
        }



        public bool isChatMessage(string content, Hashtable htUserWechat)
        {
            bool isChatMsg = false;
            try
            {
                if(!content.Contains("@"))
                {
                    return isChatMsg;
                }
                //foreach(UserBean userBean in arListUser)
                foreach(DictionaryEntry de in htUserWechat)
                {
                    UserBean userBean = (UserBean)de.Value;
                    string userName = userBean.userName;
                    string key = "@" + userName;
                    if(content.Contains(key))
                    {
                        isChatMsg = true;
                    }
                }
            }
            catch(Exception ex)
            {

            }
            return isChatMsg;
        }

        

        public string getNextDesProvince(string strMemo)
        {
            string strProvince = "";
            try
            {
                if (strMemo.Contains("发往"))
                {
                    strMemo = strMemo.Substring(strMemo.IndexOf("发往") + 2);
                    strMemo = strMemo.Replace("【", "");
                    strMemo = strMemo.Replace("】", "");
                    strMemo = strMemo.Replace("-", "");
                    strMemo = strMemo.Trim();
                    if (strMemo.Length > 2)
                    {
                        strMemo = strMemo.Substring(0, 2);
                    }
                    strProvince = getFullProvince(strMemo);

                }
            }
            catch (Exception ex)
            {

            }
            return strProvince;
        }




        public string getFullProvince(string strProPrefix)
        {
            string strRes = strProPrefix;
            try
            {
                foreach (DictionaryEntry de in StoParams.Instance.ht_sto_province_day)
                {
                    string province = de.Key.ToString();
                    if (province.Contains(strProPrefix))
                    {
                        strRes = province;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {

            }
            return strRes;
        }

        public void fillYizhanOrAssignTime(RoadInfo roadInfo, string Memo, string ScanDate, string scanType)
        {
            try
            {
                if ((Memo.StartsWith("客户签收") || Memo.StartsWith("已签收")) && !Memo.EndsWith("派件"))
                {
                    return;
                }
                if (Memo.EndsWith("-派件中") || Memo.Contains("正在派送途中"))
                {
                    roadInfo.assignPackTime = ScanDate;
                    return;
                }
                if (roadInfo.assignPackTime == "" && (!utility.Utility.isPackToYizhan(Memo, scanType)))
                {
                    roadInfo.assignPackTime = ScanDate;
                }
                else if (utility.Utility.isPackToYizhan(Memo, scanType))
                {
                    roadInfo.yizhanRecTime = ScanDate;
                }
                else
                {
                    if (!Memo.Contains("错发件"))
                    {
                        roadInfo.assignPackTime = ScanDate;
                    }

                }


            }
            catch (Exception ex)
            {

            }
        }

        public string getActProvince(string province)
        {
            string strRes = province;
            try
            {
                foreach (string strLine in m_arListProvince)
                {
                    if (strLine.Contains(province) && province.Length > 1)
                    {
                        strRes = strLine;
                        break;
                    }
                }

            }
            catch (Exception ex)
            {

            }
            return strRes;
        }


        public bool isStillInTransfer(RoadInfo roadInfo)
        {
            bool res = false;
            try
            {

            }
            catch (Exception ex)
            {

            }
            return res;
        }

        public string getNextDes(string strMemo)
        {
            string strNextSta = "";
            try
            {
                if (strMemo.Contains("发往") && strMemo.Contains("下一站"))
                {
                    strMemo = strMemo.Substring(strMemo.IndexOf("下一站") + 3);
                    strMemo = strMemo.Replace("，", ",");
                    if (strMemo.Contains(","))
                    {
                        strMemo = strMemo.Substring(0, strMemo.IndexOf(','));
                        strMemo = strMemo.Replace("【", "");
                        strMemo = strMemo.Replace("】", "");
                        strMemo = strMemo.Replace(" ", "");
                        strNextSta = strMemo;
                    }
                    else
                    {
                        int a = 0;
                    }

                }
            }
            catch (Exception ex)
            {

            }
            return strNextSta;
        }

        public bool IsNumeric(string str)
        {
            if (str == null || str.Length == 0)
                return false;
            ASCIIEncoding ascii = new ASCIIEncoding();
            byte[] bytestr = ascii.GetBytes(str);

            foreach (byte c in bytestr)
            {
                if (c < 48 || c > 57)
                {
                    return false;
                }
            }
            return true;
        }

        public void resetDrawCommad(WechatMsgBean wechatBean, out string msg)
        {
            msg = "成功";
            try
            {

                string content = wechatBean.content.Replace("设置艾特美工指令", "").Replace("，", ",");
                if (!content.Contains(","))
                {
                    msg = "失败,指令格式不正确，应该以 ,分割";
                    return;
                }
                content = content.Replace("：", "");
                content = content.Replace(":", "");
                string[] arr = content.Split(',');
                ArrayList arListCommand = new ArrayList();
                foreach (string val in arr)
                {
                    if (val.Trim().Length > 1)
                    {
                        FrameDecoderManager.Instance.htCommandDraw[val.Trim()] = val;
                        arListCommand.Add(val);
                    }

                }


                this.setCommandDraw();
            }
            catch (Exception x)
            {

            }
        }

        internal string getAllCodingCommand(WechatMsgBean wechatBean)
        {
            string res = "";
            try
            {
                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htCommandCoding)
                {
                    res = res + de.Key.ToString() + ","; ;
                }
                res = res.TrimEnd(',');
            }
            catch (Exception ex)
            {

            }
            return res;
        }
        internal string getAllChangeCodingCommand(WechatMsgBean wechatBean)
        {
            string res = "";
            try
            {
                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htCommandChangeCoding)
                {
                    res = res + de.Key.ToString() + ","; ;
                }
                res = res.TrimEnd(',');
            }
            catch (Exception ex)
            {

            }
            return res;
        }
        internal string getAllCheckCommand(WechatMsgBean wechatBean)
        {
            string res = "";
            try
            {
                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htCommandCheck)
                {
                    res = res + de.Key.ToString() + ","; ;
                }
                res = res.TrimEnd(',');
            }
            catch (Exception ex)
            {

            }
            return res;
        }

        internal string getAllQuestionCommand(WechatMsgBean wechatBean)
        {
            string res = "";
            try
            {
                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htCommandQuestion)
                {
                    res = res + de.Key.ToString() + ","; ;
                }
                res = res.TrimEnd(',');
            }
            catch (Exception ex)
            {

            }
            return res;
        }


        internal string getAllDrawCommand(WechatMsgBean wechatBean)
        {
            string res = "";
            try
            {
                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htCommandDraw)
                {
                    res = res + de.Key.ToString() + ","; ;
                }
                res = res.TrimEnd(',');
            }
            catch (Exception ex)
            {

            }
            return res;
        }

        internal string getAllGendanCommand(WechatMsgBean wechatBean)
        {
            string res = "";
            try
            {
                foreach(DictionaryEntry de in FrameDecoderManager.Instance.htCommandGendan)
                {
                    res = res + de.Key.ToString()+",";
                }
                res = res.TrimEnd(',');
            }
            catch(Exception ex)
            {

            }
            return res;

        }

        public void resetCodingCommad(WechatMsgBean wechatBean, out string msg)
        {
            msg = "成功";
            try
            {

                string content = wechatBean.content.Replace("设置艾特编码指令", "").Replace("，", ",");
                if (!content.Contains(","))
                {
                    msg = "失败,指令格式不正确，应该以 ,分割";
                    return;
                }
                content = content.Replace("：", "");
                content = content.Replace(":", "");
                string[] arr = content.Split(',');
                ArrayList arListCommand = new ArrayList();
                foreach (string val in arr)
                {
                    if (val.Trim().Length > 1)
                    {
                        FrameDecoderManager.Instance.htCommandCoding[val.Trim()] = val;
                        arListCommand.Add(val);
                    }

                }


                this.setCommandCoding();
            }
            catch (Exception x)
            {

            }
        }


        public void resetChangeCodingCommad(WechatMsgBean wechatBean, out string msg)
        {
            msg = "成功";
            try
            {

                string content = wechatBean.content.Replace("设置改编码指令", "").Replace("，", ",");
                if (!content.Contains(","))
                {
                    msg = "失败,指令格式不正确，应该以 ,分割";
                    return;
                }
                content = content.Replace("：", "");
                content = content.Replace(":", "");
                string[] arr = content.Split(',');
                ArrayList arListCommand = new ArrayList();
                foreach (string val in arr)
                {
                    if (val.Trim().Length > 1)
                    {
                        FrameDecoderManager.Instance.htCommandChangeCoding[val.Trim()] = val;
                        arListCommand.Add(val);
                    }

                }


                this.setChangeCommandCoding();
            }
            catch (Exception x)
            {

            }
        }


        internal void resetCommadnCheck(WechatMsgBean wechatBean, out string msg)
        {
            msg = "成功";
            try
            {

                string content = wechatBean.content.Replace("设置审单指令", "").Replace("，", ",");
                if (!content.Contains(","))
                {
                    msg = "失败,指令格式不正确，应该以 ,分割";
                    return;
                }
                content = content.Replace("：", "");
                content = content.Replace(":", "");
                string[] arr = content.Split(',');
                ArrayList arListCommand = new ArrayList();
                foreach (string val in arr)
                {
                    if (val.Trim().Length > 1)
                    {
                        FrameDecoderManager.Instance.htCommandCheck[val] = val;
                        arListCommand.Add(val);
                    }

                }


                this.setCommandCheck();
            }
            catch (Exception x)
            {

            }
        }

        private void setCommandCheck()
        {
            try
            {
                Hashtable htWechatMap = new Hashtable();
                StringBuilder sb = new StringBuilder();
                ArrayList arListAllLines = new ArrayList();

                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htCommandCheck)
                {
                    string commadn = de.Key.ToString();

                    arListAllLines.Add(commadn);

                }
                logHelp.LogHelper.Instance.writeConfig(StoParams.Instance.allCheckCommandTxtPath, arListAllLines);

            }
            catch (Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog(" setCommandQuestion ex" + ex.ToString());
            }
        }

        internal void removeCommadCheck(WechatMsgBean wechatBean, out string msg)
        {
            msg = "成功";
            try
            {

                string content = wechatBean.content.Replace("取消审单指令", "").Replace("，", ",");
                content = content.Replace("：", "");
                content = content.Replace(":", "");

                string[] arr = content.Split(',');
                ArrayList arListCommand = new ArrayList();
                foreach (string val in arr)
                {
                    if (val.Trim().Length > 1)
                    {
                        arListCommand.Add(val);
                        if (FrameDecoderManager.Instance.htCommandCheck.ContainsKey(val.Trim()))
                        {
                            FrameDecoderManager.Instance.htCommandCheck.Remove(val.Trim());
                        }
                    }

                }


                this.setCommandCheck();
            }
            catch (Exception x)
            {

            }
        }

        internal void removeCommadQuestion(WechatMsgBean wechatBean, out string msg)
        {
            msg = "成功";
            try
            {

                string content = wechatBean.content.Replace("取消疑问指令", "").Replace("，", ",");
                content = content.Replace("：", "");
                content = content.Replace(":", "");

                string[] arr = content.Split(',');
                ArrayList arListCommand = new ArrayList();
                foreach (string val in arr)
                {
                    if (val.Trim().Length > 1)
                    {
                        arListCommand.Add(val);
                        if (FrameDecoderManager.Instance.htCommandQuestion.ContainsKey(val.Trim()))
                        {
                            FrameDecoderManager.Instance.htCommandQuestion.Remove(val.Trim());
                        }
                    }

                }


                this.setCommandQuestion();
            }
            catch (Exception x)
            {

            }
        }

        internal void resetCommadnQuestion(WechatMsgBean wechatBean, out string msg)
        {
            msg = "成功";
            try
            {

                string content = wechatBean.content.Replace("设置疑问指令", "").Replace("，", ",");
                if (!content.Contains(","))
                {
                    msg = "失败,指令格式不正确，应该以 ,分割";
                    return;
                }
                content = content.Replace("：", "");
                content = content.Replace(":", "");
                string[] arr = content.Split(',');
                ArrayList arListCommand = new ArrayList();
                foreach (string val in arr)
                {
                    if (val.Trim().Length >= 1)
                    {
                        FrameDecoderManager.Instance.htCommandQuestion[val.Trim()] = val;
                        arListCommand.Add(val);
                    }

                }


                this.setCommandQuestion();
            }
            catch (Exception x)
            {

            }
        }

        private void setCommandQuestion()
        {
            try
            {
                Hashtable htWechatMap = new Hashtable();
                StringBuilder sb = new StringBuilder();
                ArrayList arListAllLines = new ArrayList();

                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htCommandQuestion)
                {
                    string commadn = de.Key.ToString();

                    arListAllLines.Add(commadn);

                }
                logHelp.LogHelper.Instance.writeConfig(StoParams.Instance.allQuestionCommandTxtPath, arListAllLines);

            }
            catch (Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog(" setCommandQuestion ex" + ex.ToString());
            }
        }

        public void handleRoadInfoTime(RoadInfo roadInfo, Hashtable htFarProvince)
        {
            //StoParams.Instance.register_site = "江苏盱眙公司";
            try
            {
                DateTime dtPriorSta = System.DateTime.Now; ;
                string strNextSta = "";
                string strPriorSta = "";
                DateTime dtArrivalSiteTime = System.DateTime.Now;
                string strArrivaCY = "";
                string strLastScanType = "";
                string strFirstZyCenterName = "";
                MemInfo priorMemInfo = new bean.MemInfo();
                int curIndex = 0;
                string strTerminalCompany = "";
                foreach (string strLine in roadInfo.arListMems)
                {
                    string[] arr = strLine.Split('\t');
                    if (arr.Length < 4)
                    {
                        continue;
                    }
                    if ((arr[1].Trim() == "货样" && !arr[0].Contains(":")) || IsNumeric(arr[0].Trim()) || arr[0].Trim() == "货样")
                    {
                        continue;
                    }
                    string strUploadSite = arr[1];
                    string strType = arr[2].ToString();
                    if (strType.Contains("签收") || strType.Contains("代收"))
                    {
                        strTerminalCompany = strUploadSite;
                    }
                }
                curIndex = 0;
                bool isCurStaZY = false;
                string strLastProvince = "";
                string strLastSiteName = "";
                string strLastScanStatus = "";
                foreach (string strLine in roadInfo.arListMems)
                {
                    curIndex++;
                    string[] arr = strLine.Split('\t');
                    if (arr.Length < 4)
                    {
                        continue;
                    }

                    if ((arr[1].Trim() == "货样" && !arr[0].Contains(":")) || IsNumeric(arr[0].Trim()) || arr[0].Trim() == "货样")
                    {
                        continue;
                    }
                    DateTime dtOpTime = Convert.ToDateTime(arr[0].Trim());

                    roadInfo.lastSiteScanDate = dtOpTime.ToString();
                    if (arr[1].Contains("集散中心") || arr[1].Contains("转运中心") || arr[1].Contains("分拨") || arr[1].Contains("航空部"))
                    {
                        if (strFirstZyCenterName == "")
                        {
                            strFirstZyCenterName = arr[1];
                        }
                        isCurStaZY = true;
                    }
                    string strUploadSite = arr[1];
                    string strType = arr[2].ToString();
                    strLastSiteName = strUploadSite;
                    strLastScanStatus = strType;



                    if (arr[1] == strFirstZyCenterName)
                    {

                        continue;
                    }

                    if (curIndex < 5 && strUploadSite == StoParams.Instance.register_site)
                    {
                        roadInfo.isSendFromMySite = true;
                        if (strType.Contains("收件"))
                        {
                            roadInfo.lanshouTime = arr[0];
                        }
                        if (strType.Contains("发件"))
                        {
                            roadInfo.depMySiteSendTime = arr[0];
                        }
                    }
                    if ((strType.Contains("收件") || strUploadSite == StoParams.Instance.register_site) && curIndex < 5)
                    {

                        continue;
                    }
                    string province = "";
                    if (strUploadSite.Length > 2)
                    {
                        province = UtilityHelp.Instance.getFullProvince(strUploadSite.Substring(0, 2));
                    }

                    province = UtilityHelp.Instance.getActProvince(province);
                    if (province.Length > 0)
                    {
                        strLastProvince = province;
                        roadInfo.province = strLastProvince;
                    }


                    if (priorMemInfo.uploadSiteName == strUploadSite)
                    {
                        if (priorMemInfo.arrivalTime != "")
                        {
                            //判断快件在当前转运中心是否超时
                            DateTime dtPriorArrivalTime = Convert.ToDateTime(priorMemInfo.arrivalTime);
                            TimeSpan ts = dtOpTime - dtPriorArrivalTime;
                            if (strType.Contains("退回件"))
                            {
                                priorMemInfo.isReturnPackage = true;
                            }
                            if (!strType.Contains("签收") && !strType.Contains("代收") && strUploadSite != strTerminalCompany)
                            {
                                int totalDelayDefineHours = 72;
                                if (priorMemInfo.isReturnPackage)
                                {
                                    totalDelayDefineHours = 96;
                                }
                                if (ts.TotalHours > totalDelayDefineHours)
                                {
                                    roadInfo.isZYCenterDalay = true;
                                    roadInfo.DelayedZyName = strUploadSite;
                                    string strHeader = "";
                                    if (isCurStaZY)
                                    {
                                        strHeader = "转运中心";
                                    }
                                    roadInfo.strErrorMsg = strHeader + "滞留延误";
                                }
                            }

                        }

                    }
                    else
                    {
                        //中转延误
                        if (priorMemInfo.sendTime != "" && !strType.Contains("签收") && !strType.Contains("代收"))
                        {
                            DateTime dtPriorSiteSendTime = Convert.ToDateTime(priorMemInfo.sendTime);
                            TimeSpan ts = dtOpTime - dtPriorSiteSendTime;
                            int totalDelayDef = 72;
                            if (strUploadSite.Length > 2)
                            {
                                if (htFarProvince.ContainsKey(province))
                                {
                                    totalDelayDef = 120;
                                }
                            }



                            if (ts.TotalHours > totalDelayDef)
                            {
                                roadInfo.isZYCenterDalay = true;
                                roadInfo.DelayedZyName = strPriorSta;
                                string strHeader = "";
                                if (isCurStaZY)
                                {
                                    strHeader = "转运中心";
                                }
                                roadInfo.strErrorMsg = strHeader + "中转延误";
                            }

                        }
                        priorMemInfo = new MemInfo();
                        priorMemInfo.uploadSiteName = strUploadSite;
                        if (strType.Contains("到件") || strType.Contains("卸车"))
                        {
                            priorMemInfo.arrivalTime = arr[0].Trim();
                        }

                        if (strType.Contains("发件"))
                        {
                            priorMemInfo.sendTime = arr[0].Trim();


                        }

                    }

                    if (arr[3].Contains("超派件,客户自取") && strType.Contains("问题件"))
                    {
                        roadInfo.isChaoPaiPackage = true;
                    }
                    if (strType == "驿站代收" && roadInfo.yizhanRecTime == "" && curIndex > roadInfo.arListMems.Count - 6)
                    {
                        roadInfo.yizhanRecTime = dtOpTime.ToString();
                        roadInfo.isDonePack = true;
                        roadInfo.DonePackSite = arr[1];
                        roadInfo.lastSiteName = strUploadSite;
                    }
                    if (strType.Contains("签收") && roadInfo.donePackTime == "" && curIndex > roadInfo.arListMems.Count - 6)
                    {
                        roadInfo.donePackTime = dtOpTime.ToString();
                        roadInfo.isDonePack = true;
                        roadInfo.DonePackSite = arr[1];
                        roadInfo.lastScanStatus = "签收";
                        roadInfo.lastSiteName = strUploadSite;
                        if (strUploadSite == StoParams.Instance.register_site)
                        {
                            roadInfo.isReturnPackage = true;
                        }
                    }


                    priorMemInfo.uploadSiteName = strUploadSite;
                    if (strType.Contains("到件"))
                    {
                        priorMemInfo.arrivalTime = arr[0].Trim();
                    }
                    if (strType.Contains("卸车"))
                    {
                        priorMemInfo.arrivalTime = arr[0].Trim();
                    }
                    if (strType.Contains("发件"))
                    {
                        priorMemInfo.sendTime = arr[0].Trim();
                        if (!roadInfo.isDonePack)
                        {
                            roadInfo.lastSendTime = arr[0].Trim();
                        }

                        priorMemInfo.sendTime = arr[0].Trim();
                        strNextSta = UtilityHelp.instance.getNextDes(strLine);
                        string strKey = arr[1] + "-" + strNextSta;
                        if (StoParams.Instance.htSiteTimeMap.ContainsKey(strKey))
                        {
                            TimeBean timeBean = StoParams.Instance.htSiteTimeMap[strKey] as TimeBean;

                            int nAddDays = 0;
                            try
                            {
                                nAddDays = Convert.ToInt32(timeBean.addDays);
                                DateTime dtSendTime = Convert.ToDateTime(priorMemInfo.sendTime);
                                DateTime dtSendTimeLast = Convert.ToDateTime(dtSendTime.ToShortDateString() + " " + "23:59:59");
                                dtSendTimeLast = dtSendTimeLast.AddDays(nAddDays);
                                DateTime dtDanPaiTime = Convert.ToDateTime(dtSendTime.ToShortDateString() + " " + timeBean.firstAssignTime);
                                if (dtSendTime < dtDanPaiTime)
                                {
                                    roadInfo.actConculTime = dtSendTimeLast.ToString();
                                }
                                else
                                {
                                    roadInfo.actConculTime = dtSendTimeLast.AddDays(1).ToString();
                                }
                            }
                            catch (Exception ex)
                            {

                            }
                        }

                    }

                    strLastScanType = strType;
                    priorMemInfo.scanType = strType;
                    priorMemInfo.scanTime = dtOpTime.ToString();

                }
                if (!roadInfo.isDonePack)
                {
                    roadInfo.lastScanStatus = strLastScanStatus;
                    roadInfo.lastSiteName = strLastSiteName;
                }

            }
            catch (Exception ex)
            {

            }
        }

        public void setRoomFilterWechat(WechatMsgBean wechatBean)
        {
            try
            {
                if(!FrameDecoderManager.Instance.htAllRoomsFilters.ContainsKey(wechatBean.roomid))
                {
                    ArrayList arListFilter = new ArrayList();
                    arListFilter.Add(wechatBean.from);
                    FrameDecoderManager.Instance.htAllRoomsFilters[wechatBean.roomid] = arListFilter;
                    setUserFilterWechat();
                }
                else
                {
                    ArrayList arListFilter = FrameDecoderManager.Instance.htAllRoomsFilters[wechatBean.roomid] as ArrayList;
                    if(!arListFilter.Contains(wechatBean.from))
                    {
                        arListFilter.Add(wechatBean.from);
                    }
                    FrameDecoderManager.Instance.htAllRoomsFilters[wechatBean.roomid] = arListFilter;
                    setUserFilterWechat();
                }
            }
            catch(Exception ex)
            {

            }
        }




        public void setRoomDrawingWechat(WechatMsgBean wechatBean)
        {
            try
            {

                if (!FrameDecoderManager.Instance.htDrawingRoomsUsers.ContainsKey(wechatBean.roomid))
                {
                    //logHelp.LogHelper.Instance.writeLog("不包含roomid "+ wechatBean.roomid+" atUserListCount="+ wechatBean.atUserList.Count.ToString());
                    ArrayList arListFilter = new ArrayList();
                    foreach (string userWxid in wechatBean.atUserList)
                    {
                        arListFilter.Add(userWxid);
                        //logHelp.LogHelper.Instance.writeLog("@user:" + userWxid);
                    }

                    FrameDecoderManager.Instance.htDrawingRoomsUsers[wechatBean.roomid] = arListFilter;
                    setDwawUserFilterWechat();
                }
                else
                {
                    ArrayList arListFilter = FrameDecoderManager.Instance.htDrawingRoomsUsers[wechatBean.roomid] as ArrayList;

                    foreach (string userWxid in wechatBean.atUserList)
                    {
                        if (!arListFilter.Contains(userWxid))
                        {
                            arListFilter.Add(userWxid);
                        }

                    }
                    FrameDecoderManager.Instance.htDrawingRoomsUsers[wechatBean.roomid] = arListFilter;
                    this.setDwawUserFilterWechat();
                }
            }
            catch (Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog("设置美工 ex:"+ ex.ToString());
            }
        }


        public void batchSetRoomDrawingWechat(WechatMsgBean wechatBean)
        {
            try
            {
                foreach(DictionaryEntry de in FrameDecoderManager.Instance.htDrawingRoomsUsers)
                {
                    string room = de.Key.ToString();
                    ArrayList arListFilter = (ArrayList)de.Value;
                    foreach (string userWxid in wechatBean.atUserList)
                    {
                        if (!arListFilter.Contains(userWxid))
                        {
                            arListFilter.Add(userWxid);
                        }

                    }
                    ArrayList arListDel = new ArrayList();
                    foreach(string userID in arListFilter)
                    {
                        if (!wechatBean.atUserList.Contains(userID))
                        {
                            arListDel.Add(userID);
                        }

                    }
                    foreach(string ueserID in arListDel)
                    {
                        if(arListFilter.Contains(ueserID))
                        {
                            arListFilter.Remove(ueserID);
                        }
                    }
                }               

                              
                this.setDwawUserFilterWechat();
            }
            catch (Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog("批量设置美工 ex:" + ex.ToString());
            }
        }


        public void batchSetCustomerEmpWechat(WechatMsgBean wechatBean)
        {
            try
            {
                FrameDecoderManager.Instance.htCustomerServiceRoomsUsers.Clear();
                foreach (string wxid in wechatBean.atUserList)
                {
                    FrameDecoderManager.Instance.htCustomerServiceRoomsUsers[wxid] = wxid;
                }


                this.setCustomerServiceWechat();
            }
            catch (Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog("批量设置美工 ex:" + ex.ToString());
            }
        }



        public void batchSetRoomCodingWechat(WechatMsgBean wechatBean)
        {
            try
            {
                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htCodingRoomsUsers)
                {
                    string room = de.Key.ToString();
                    ArrayList arListFilter = (ArrayList)de.Value;
                    foreach (string userWxid in wechatBean.atUserList)
                    {
                        if (!arListFilter.Contains(userWxid))
                        {
                            arListFilter.Add(userWxid);
                        }

                    }
                    ArrayList arListDel = new ArrayList();
                    foreach (string userID in arListFilter)
                    {
                        if (!wechatBean.atUserList.Contains(userID))
                        {
                            arListDel.Add(userID);
                        }

                    }
                    foreach (string ueserID in arListDel)
                    {
                        if (arListFilter.Contains(ueserID))
                        {
                            arListFilter.Remove(ueserID);
                        }
                    }
                }


                this.setCodingUserFilterWechat();
            }
            catch (Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog("批量设置编码 ex:" + ex.ToString());
            }
        }




        public void resetRoomDrawingWechat(WechatMsgBean wechatBean)
        {
            try
            {

                if (!FrameDecoderManager.Instance.htDrawingRoomsUsers.ContainsKey(wechatBean.roomid))
                {
                    //logHelp.LogHelper.Instance.writeLog("不包含roomid "+ wechatBean.roomid+" atUserListCount="+ wechatBean.atUserList.Count.ToString());
                    ArrayList arListFilter = new ArrayList();
                    foreach (string userWxid in wechatBean.atUserList)
                    {
                        //arListFilter.Add(userWxid);
                        //logHelp.LogHelper.Instance.writeLog("@user:" + userWxid);
                    }

                    FrameDecoderManager.Instance.htDrawingRoomsUsers[wechatBean.roomid] = arListFilter;
                    setDwawUserFilterWechat();
                }
                else
                {
                    ArrayList arListFilter = FrameDecoderManager.Instance.htDrawingRoomsUsers[wechatBean.roomid] as ArrayList;

                    arListFilter.Clear();
                    /*foreach (string userWxid in wechatBean.atUserList)
                    {
                        if (!arListFilter.Contains(userWxid))
                        {
                            arListFilter.Add(userWxid);
                        }

                    }*/
                    FrameDecoderManager.Instance.htDrawingRoomsUsers[wechatBean.roomid] = arListFilter;
                    this.setDwawUserFilterWechat();
                }
            }
            catch (Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog("设置美工 ex:" + ex.ToString());
            }
        }



        public void setInternalWechat(WechatMsgBean wechatBean)
        {
            try
            {
                foreach (string userWxid in wechatBean.atUserList)
                {
                    FrameDecoderManager.Instance.htForbiddenDeliverUsers[userWxid] = "";
                }


                this.setInternalWechat();

              
            }
            catch (Exception ex)
            {

            }
        }


        public void setInternalWechat()
        {
            try
            {
                Hashtable htWechatMap = new Hashtable();
                StringBuilder sb = new StringBuilder();
                ArrayList arListAllLines = new ArrayList();
                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htForbiddenDeliverUsers)
                {
                    string userID = de.Key.ToString();
                    sb.AppendLine(userID);
                    arListAllLines.Add(userID);

                }
                logHelp.LogHelper.Instance.writeConfig(StoParams.Instance.allInternalUserTxtPath, arListAllLines);

            }
            catch (Exception ex)
            {

            }
        }


        public void setRoomCodingWechat(WechatMsgBean wechatBean)
        {
            try
            {
                if (!FrameDecoderManager.Instance.htCodingRoomsUsers.ContainsKey(wechatBean.roomid))
                {
                    ArrayList arListFilter = new ArrayList();
                    foreach (string userWxid in wechatBean.atUserList)
                    {
                        arListFilter.Add(userWxid);
                    }

                    FrameDecoderManager.Instance.htCodingRoomsUsers[wechatBean.roomid] = arListFilter;
                    this.setCodingUserFilterWechat();
                }
                else
                {
                    ArrayList arListFilter = FrameDecoderManager.Instance.htCodingRoomsUsers[wechatBean.roomid] as ArrayList;

                    foreach (string userWxid in wechatBean.atUserList)
                    {
                        if (!arListFilter.Contains(userWxid))
                        {
                            arListFilter.Add(userWxid);
                        }

                    }
                    FrameDecoderManager.Instance.htCodingRoomsUsers[wechatBean.roomid] = arListFilter;
                    this.setCodingUserFilterWechat();
                }
            }
            catch (Exception ex)
            {

            }
        }



        public void resetRoomCodingWechat(WechatMsgBean wechatBean)
        {
            try
            {
                if (!FrameDecoderManager.Instance.htCodingRoomsUsers.ContainsKey(wechatBean.roomid))
                {
                    ArrayList arListFilter = new ArrayList();
                    foreach (string userWxid in wechatBean.atUserList)
                    {
                        //arListFilter.Add(userWxid);
                    }

                    FrameDecoderManager.Instance.htCodingRoomsUsers[wechatBean.roomid] = arListFilter;
                    this.setCodingUserFilterWechat();
                }
                else
                {
                    ArrayList arListFilter = FrameDecoderManager.Instance.htCodingRoomsUsers[wechatBean.roomid] as ArrayList;

                    arListFilter.Clear();
                    /*foreach (string userWxid in wechatBean.atUserList)
                    {
                        if (!arListFilter.Contains(userWxid))
                        {
                            arListFilter.Add(userWxid);
                        }

                    }*/
                    FrameDecoderManager.Instance.htCodingRoomsUsers[wechatBean.roomid] = arListFilter;
                    this.setCodingUserFilterWechat();
              
                }
            }
            catch (Exception ex)
            {

            }
        }

        public void setRoomFilterOtherWechat(WechatMsgBean wechatBean)
        {
            try
            {
                if (!FrameDecoderManager.Instance.htAllRoomsFilters.ContainsKey(wechatBean.roomid))
                {
                    ArrayList arListFilter = new ArrayList();
                    foreach(string userWxid in wechatBean.atUserList)
                    {
                        arListFilter.Add(userWxid);
                    }
                   
                    FrameDecoderManager.Instance.htAllRoomsFilters[wechatBean.roomid] = arListFilter;
                    setUserFilterWechat();
                }
                else
                {
                    ArrayList arListFilter = FrameDecoderManager.Instance.htAllRoomsFilters[wechatBean.roomid] as ArrayList;
               
                    foreach (string userWxid in wechatBean.atUserList)
                    {
                        if (!arListFilter.Contains(userWxid))
                        {
                            arListFilter.Add(userWxid);
                        }
                            
                    }
                    FrameDecoderManager.Instance.htAllRoomsFilters[wechatBean.roomid] = arListFilter;
                    setUserFilterWechat();
                }
            }
            catch (Exception ex)
            {

            }
        }

        public void setRoomFilterRemoveWechat(WechatMsgBean wechatBean)
        {
            try
            {
                ArrayList arListFilter = FrameDecoderManager.Instance.htAllRoomsFilters[wechatBean.roomid] as ArrayList;
                if (arListFilter.Contains(wechatBean.from))
                {
                    arListFilter.Remove(wechatBean.from);
                }
                FrameDecoderManager.Instance.htAllRoomsFilters[wechatBean.roomid] = arListFilter;
                setUserFilterWechat();
            }
            catch (Exception ex)
            {

            }
        }


        public void setRoomOtherFilterRemoveWechat(WechatMsgBean wechatBean)
        {
            try
            {
                ArrayList arListFilter = FrameDecoderManager.Instance.htAllRoomsFilters[wechatBean.roomid] as ArrayList;
                foreach(string strWxid in wechatBean.atUserList)
                {
                    if (arListFilter.Contains(strWxid))
                    {
                        arListFilter.Remove(strWxid);
                    }
                }
                
                FrameDecoderManager.Instance.htAllRoomsFilters[wechatBean.roomid] = arListFilter;
                setUserFilterWechat();
            }
            catch (Exception ex)
            {

            }
        }


        public bool isFilterWechat(WechatMsgBean wechatBean)
        {
            bool res = false;
            try
            {
                ArrayList arListFilter = FrameDecoderManager.Instance.htAllRoomsFilters[wechatBean.roomid] as ArrayList;
                if (arListFilter.Contains(wechatBean.from))
                {
                    res = true;
                }
             
            }
            catch (Exception ex)
            {

            }
            return res;
        }

        internal void addRoomLanshouConfigFile(WechatMsgBean wechatBean,string status)
        {
            try
            {
                if(status.Contains("开启"))
                {
                    FrameDecoderManager.Instance.htAllowLanshouRoom[wechatBean.roomid] = wechatBean.roomid;
                    if(FrameDecoderManager.Instance.htForbiddenLanshouRoom.ContainsKey(wechatBean.roomid))
                    {
                        FrameDecoderManager.Instance.htForbiddenLanshouRoom.Remove(wechatBean.roomid);
                    }
                }
                else
                {
                    if(FrameDecoderManager.Instance.htAllowLanshouRoom.ContainsKey(wechatBean.roomid))
                    {
                        FrameDecoderManager.Instance.htAllowLanshouRoom.Remove(wechatBean.roomid);
                    }
                    FrameDecoderManager.Instance.htForbiddenLanshouRoom[wechatBean.roomid] = wechatBean.roomid;
                }
               
                ArrayList arListAllLines = new ArrayList();
                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htAllowLanshouRoom)
                {
                    arListAllLines.Add(de.Key.ToString());
                }

                if (arListAllLines.Count > 0)
                {
                    logHelp.LogHelper.Instance.writeConfig(StoParams.Instance.allowLanshouRoomsTxtPath, arListAllLines);
                }


                arListAllLines.Clear();
                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htForbiddenLanshouRoom)
                {
                    arListAllLines.Add(de.Key.ToString());
                }

                if (arListAllLines.Count > 0)
                {
                    logHelp.LogHelper.Instance.writeConfig(StoParams.Instance.forbiddenLanshouRoomsTxtPath, arListAllLines);
                }




            }
            catch (Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog("addRoomLanshouConfigFile:" + ex.ToString());
            }
        }


        internal void addRoomConfigFile(WechatMsgBean wechatBean)
        {
            try
            {
                FrameDecoderManager.Instance.htAllRooms[wechatBean.roomid] = wechatBean.roomid;
                ArrayList arListAllLines = new ArrayList();
                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htAllRooms)
                {
                    arListAllLines.Add(de.Key.ToString());
                }

                if (arListAllLines.Count > 0)
                {
                    logHelp.LogHelper.Instance.writeConfig(StoParams.Instance.allRoomsTxtPath, arListAllLines);
                }
                if(!FrameDecoderManager.Instance.arListNewRegSite.Contains(wechatBean.roomid))
                {
                    if(FrameDecoderManager.Instance.arListNewRegSite.Count>0)
                    {
                        string lastRegRoom = FrameDecoderManager.Instance.arListNewRegSite[FrameDecoderManager.Instance.arListNewRegSite.Count - 1].ToString();
                        if(FrameDecoderManager.Instance.htAllRoomsFilters.ContainsKey(lastRegRoom))
                        {
                            ArrayList arList = FrameDecoderManager.Instance.htAllRoomsFilters[lastRegRoom] as ArrayList;
                            ArrayList arListNewFilter = new ArrayList();
                            foreach (string steLine in arList)
                            {
                                arListNewFilter.Add(steLine);
                            }
                            FrameDecoderManager.Instance.htAllRoomsFilters[lastRegRoom] = arListNewFilter;
                        }
                    }
                    FrameDecoderManager.Instance.arListNewRegSite.Add(wechatBean.roomid);

                    if (!FrameDecoderManager.Instance.htDrawingRoomsUsers.ContainsKey(wechatBean.roomid))
                    {
                        FrameDecoderManager.Instance.htDrawingRoomsUsers[wechatBean.roomid] = new ArrayList();
                    }

                    if (!FrameDecoderManager.Instance.htCodingRoomsUsers.ContainsKey(wechatBean.roomid))
                    {
                        FrameDecoderManager.Instance.htCodingRoomsUsers[wechatBean.roomid] = new ArrayList();
                    }


                }
                

            }
            catch(Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog("addRoomConfigFile:" + ex.ToString());
            }
        }




        internal void addRoomEmployeeConfigFile(WechatMsgBean wechatBean)
        {
            try
            {
                FrameDecoderManager.Instance.htRoomaATEmployee[wechatBean.roomid] = wechatBean.from;
                ArrayList arListAllLines = new ArrayList();
                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htRoomaATEmployee)
                {
                    arListAllLines.Add(de.Key.ToString()+ ":" + de.Value.ToString());
                }
                logHelp.LogHelper.Instance.writeLog("配置room employee  wechatBean.from" + wechatBean.from + " wechatRoom:" + wechatBean.roomid);
                if (arListAllLines.Count > 0)
                {
                    logHelp.LogHelper.Instance.writeConfig(StoParams.Instance.allRoomsEmplyeeTxtPath, arListAllLines);
                }
             


            }
            catch (Exception ex)
            {

            }
        }


        internal bool addRoomGroupConfigFile(WechatMsgBean wechatBean)
        {
            bool res = false;
            try
            {
                //FrameDecoderManager.Instance.htRoomaATEmployee[wechatBean.roomid] = wechatBean.from;
                string content = wechatBean.content.Replace("：", "");
                if(content.Contains(":"))
                {
                    string[] arr = content.Split(':');
                    if(!FrameDecoderManager.Instance.htGroupNameRooms.ContainsKey(wechatBean.roomid))
                    {
                        FrameDecoderManager.Instance.htGroupNameRooms[wechatBean.roomid] = arr[1];
                    }
                    ArrayList arListAllLines = new ArrayList();
                    foreach (DictionaryEntry de in FrameDecoderManager.Instance.htGroupNameRooms)
                    {
                        arListAllLines.Add(de.Key.ToString() + ":" + de.Value.ToString());
                    }
                    logHelp.LogHelper.Instance.writeLog("配置group name rppm " + wechatBean.from + " wechatRoom:" + wechatBean.roomid);
                    if (arListAllLines.Count > 0)
                    {
                        logHelp.LogHelper.Instance.writeConfig(StoParams.Instance.GroupRoomPath, arListAllLines);
                        res = true;
                    }
                }
                



            }
            catch (Exception ex)
            {

            }
            return res;
        }

        public SiteBean getFirstSite(string strContent,ArrayList arListRoadMap)
        {
            SiteBean siteBean = new bean.SiteBean();
            SiteBean priorSiteBean = new bean.SiteBean();
            try
            {
                JObject jsonObj = (JObject)JsonConvert.DeserializeObject(strContent);
                JArray dataArray = (JArray)jsonObj["data"];
                string siteBeanName = "";

                if (dataArray.Count > 0)
                {
                    jsonObj = (JObject)dataArray[0];
                    siteBean.siteCode = jsonObj["code"].ToString();
                    siteBean.siteName = jsonObj["name"].ToString();
                    siteBean.siteId = jsonObj["id"].ToString();
                    siteBeanName = jsonObj["name"].ToString();
                    priorSiteBean.siteCode = siteBean.siteCode;
                    priorSiteBean.siteName = siteBean.siteName;
                    priorSiteBean.siteId = siteBean.siteId;
                }
                string lanshouSite = "";
                foreach (RoadBean roadBean in arListRoadMap)
                {
                    if(roadBean.lanshouSite!="")
                    {
                        lanshouSite = roadBean.lanshouSite;
                        break;
                    }
                }
                if(lanshouSite== siteBean.siteName)
                {
                    jsonObj = (JObject)dataArray[1];
                    siteBean.siteCode = jsonObj["code"].ToString();
                    siteBean.siteName = jsonObj["name"].ToString();
                    siteBean.siteId = jsonObj["id"].ToString();
                    siteBeanName = jsonObj["name"].ToString();
                    priorSiteBean.siteCode = siteBean.siteCode;
                    priorSiteBean.siteName = siteBean.siteName;
                    priorSiteBean.siteId = siteBean.siteId;
                }

                RoadBean lastRoadBean = new RoadBean();
                foreach (RoadBean roadBean in arListRoadMap)
                {
                    lastRoadBean = roadBean;
                    if (roadBean.scanNetworkName== siteBeanName)
                    {
                        string strScanType = roadBean.scanTypeName;
                        if(strScanType.Contains("发件") && (siteBean.siteName.Contains("转运")|| siteBean.siteName.Contains("分拨")|| siteBean.siteName.Contains("集散")))
                        {
                            //if(roadBean.nextStopName.Contains("网点")&& roadBean.nextStopWorkID!="")
                            if ( roadBean.nextStopWorkID != "")
                            {
                                siteBean.siteCode = roadBean.nextNetworkCode;
                                siteBean.siteName = roadBean.nextStopName;
                                siteBean.siteId = roadBean.nextStopWorkID;
                            }
                        }
                    }
                }

                if(lastRoadBean.scanNetworkName== siteBeanName&& (lastRoadBean.scanTypeName== "问题件扫描"|| lastRoadBean.scanTypeName.Contains("到件") || lastRoadBean.scanTypeName.Contains("退件扫描")))
                {
                    siteBean = priorSiteBean;
                }
            }
            catch (Exception ex)
            {

            }

            return siteBean;
        }


        public SiteBean getBeanSite(ArrayList arListRoadMap)
        {
            SiteBean siteBean = new bean.SiteBean();
            try
            {
                RoadBean lastRoadBean = (RoadBean)arListRoadMap[arListRoadMap.Count - 1];
                if(lastRoadBean.scanTypeName.Contains("发件扫描") || lastRoadBean.scanTypeName.Contains("装车发件"))
                {
                    if(lastRoadBean.nextStopName== StoParams.Instance.register_site)
                    {
                        siteBean.siteName = StoParams.Instance.register_site;
                        return siteBean;
                    }
                    if (lastRoadBean.nextStopWorkID != "")
                    {
                        siteBean.siteCode = lastRoadBean.nextNetworkCode;
                        siteBean.siteName = lastRoadBean.nextStopName;
                        siteBean.siteId = lastRoadBean.nextStopWorkID;
                    }
                }
                else
                {
                    foreach (RoadBean roadBean in arListRoadMap)
                    {
                        string strScanType = roadBean.scanTypeName;
                        if (strScanType.Contains("发件扫描") || strScanType == "装车发件")
                        {
                            //if(roadBean.nextStopName.Contains("网点")&& roadBean.nextStopWorkID!="")
                            if (roadBean.nextStopWorkID != "")
                            {
                                siteBean.siteCode = roadBean.nextNetworkCode;
                                siteBean.siteName = roadBean.nextStopName;
                                siteBean.siteId = roadBean.nextStopWorkID;
                            }
                        }
                        else
                        {
                            if (strScanType.Contains("卸车扫描")|| strScanType.Contains("到件"))
                            {
                                siteBean.siteCode = roadBean.scanNetworkCode;
                                siteBean.siteName = roadBean.scanNetworkName;
                                siteBean.siteId = roadBean.scanStieWorkID;
                            }

                            else if (strScanType.Contains("出仓")|| strScanType.Contains("入库"))
                            {
                                if(roadBean.scanStieWorkID!="")
                                {
                                    siteBean.siteCode = roadBean.scanNetworkCode;
                                    siteBean.siteName = roadBean.scanNetworkName;
                                    siteBean.siteId = roadBean.scanStieWorkID;
                                }
                                
                            }

                            else if (strScanType.Contains("快件签收"))
                            {
                                if (roadBean.scanStieWorkID != "")
                                {
                                    siteBean.siteCode = roadBean.scanNetworkCode;
                                    siteBean.siteName = roadBean.scanNetworkName;
                                    siteBean.siteId = roadBean.scanStieWorkID;
                                }
                                    
                            }
                        }
                    }
                }
                
            }
            catch (Exception ex)
            {

            }

            return siteBean;
        }


        

        public SiteBean getBeanSiteDirtyParcel(ArrayList arListRoadMap)
        {
            SiteBean siteBean = new bean.SiteBean();
            try
            {

                foreach (RoadBean roadBean in arListRoadMap)
                {
                    string strScanType = roadBean.scanTypeName;
                    if(strScanType.Contains("问题件"))
                    {
                        if(roadBean.waybillTrackingContent.Contains("变形"))
                        {
                            if(StoParams.Instance.register_site!= roadBean.scanNetworkName)
                            {
                                siteBean.siteCode = roadBean.scanNetworkCode;
                                siteBean.siteName = roadBean.scanNetworkName;
                                siteBean.siteId = roadBean.scanStieWorkID;
                                return siteBean;
                            }
                        }
                    }
       
                }


                RoadBean lastRoadBean = (RoadBean)arListRoadMap[arListRoadMap.Count - 1];
                if (lastRoadBean.scanTypeName.Contains("发件扫描") || lastRoadBean.scanTypeName.Contains("装车发件"))
                {
                    if (lastRoadBean.nextStopName == StoParams.Instance.register_site)
                    {
                        siteBean.siteName = StoParams.Instance.register_site;
                        return siteBean;
                    }
                    if (lastRoadBean.nextStopWorkID != "")
                    {
                        siteBean.siteCode = lastRoadBean.nextNetworkCode;
                        siteBean.siteName = lastRoadBean.nextStopName;
                        siteBean.siteId = lastRoadBean.nextStopWorkID;
                    }
                }
                else
                {
                    foreach (RoadBean roadBean in arListRoadMap)
                    {
                        string strScanType = roadBean.scanTypeName;
                        if (strScanType.Contains("发件扫描") || strScanType == "装车发件")
                        {
                            //if(roadBean.nextStopName.Contains("网点")&& roadBean.nextStopWorkID!="")
                            if (roadBean.nextStopWorkID != "")
                            {
                                siteBean.siteCode = roadBean.nextNetworkCode;
                                siteBean.siteName = roadBean.nextStopName;
                                siteBean.siteId = roadBean.nextStopWorkID;
                            }
                        }
                        else
                        {
                            if (strScanType.Contains("卸车扫描") || strScanType.Contains("到件"))
                            {
                                siteBean.siteCode = roadBean.scanNetworkCode;
                                siteBean.siteName = roadBean.scanNetworkName;
                                siteBean.siteId = roadBean.scanStieWorkID;
                            }
                        }
                    }
                }

            }
            catch (Exception ex)
            {

            }

            return siteBean;
        }


        public SiteBean getLastSite(string strContent)
        {
            SiteBean siteBean = new bean.SiteBean();
            try
            {
                JObject jsonObj = (JObject)JsonConvert.DeserializeObject(strContent);
                JArray dataArray = (JArray)jsonObj["data"];
                if (dataArray.Count > 0)
                {
                    jsonObj = (JObject)dataArray[dataArray.Count-1];
                    siteBean.siteCode = jsonObj["code"].ToString();
                    siteBean.siteName = jsonObj["name"].ToString();
                    siteBean.siteId = jsonObj["id"].ToString();
                }
            }
            catch (Exception ex)
            {

            }

            return siteBean;
        }

        public string getProcess(int total, int curPage)
        {
            string res = "0%";
            try
            {
                res = ((double)curPage / ((double)total)).ToString("0%");
            }
            catch (Exception ex)
            {

            }
            return res;
        }

        public string getEffi(JObject obgData)
        {
            string res = "";
            try
            {
                JToken departNetworkName = obgData["departNetworkName"];
                JToken arriveNetworkName = obgData["arriveNetworkName"];
                JToken arriveNetworkCode = obgData["arriveNetworkCode"];
                JToken latestArrivalTime = obgData["latestArrivalTime"];
                JToken plannedDepartureTime = obgData["plannedDepartureTime"];

                JToken endParentNetworkName = obgData["endParentNetworkName"];
                JToken endParentNetworkCode = obgData["endParentNetworkCode"];
                JToken plannedArrivalTime = obgData["plannedArrivalTime"];
                JToken spanDaysArrive = obgData["spanDaysArrive"];
                JToken spanDaysSign = obgData["spanDaysSign"];

                JToken effectiveDate = obgData["effectiveDate"];


                if (arriveNetworkName.ToString().Contains("$") || endParentNetworkName.ToString().Contains("$")
                    || arriveNetworkName.ToString().Contains("@") || endParentNetworkName.ToString().Contains("@"))
                {
                    int a = 0;
                }
                res = departNetworkName.ToString() + "$" + arriveNetworkName.ToString() + "$" + latestArrivalTime.ToString() + "$" +
                 plannedDepartureTime.ToString() + "$" + plannedArrivalTime.ToString() + "$" + spanDaysArrive.ToString()+"$"+ spanDaysSign.ToString()+"$"+ effectiveDate.ToString();

                //res = obgData.ToString();

            }
            catch (Exception ex)
            {

            }
            return res;
        }


        public string getMainLineEffi(JObject obgData)
        {
            string res = "";
            try
            {
                JToken startName = obgData["startName"];
                JToken startCode = obgData["startCode"];
                JToken endCode = obgData["endCode"];
                JToken endName = obgData["endName"];

                JToken plannedDepartureTime = obgData["plannedDepartureTime"];
                JToken plannedArrivalTime = obgData["plannedArrivalTime"];
                JToken spanDays = obgData["spanDays"];
                JToken operateTime= obgData["operateTime"];
                JToken giveShiftsTime= obgData["giveShiftsTime"];
                JToken effectiveDate= obgData["effectiveDate"];


                string latestSHZXTime = "";
                if (latestSHZXTime != null)
                {
                    latestSHZXTime = giveShiftsTime.ToString();
                }

                if(startName.ToString().Contains("潮汕")&& endName.ToString().Contains("哈市"))
                {
                    int a = 0;
                }
       
                if (startName.ToString().Contains("$") || endName.ToString().Contains("$")
                    || startName.ToString().Contains("@") || endName.ToString().Contains("@"))
                {
                    int a = 0;
                }
                res = startCode.ToString() + "$" + endCode + "$" + startName.ToString() + "@" + endName.ToString() + "$" + startCode + "@" + endCode.ToString() + "$" + plannedDepartureTime.ToString() + "$" +
                       plannedArrivalTime.ToString() + "$" + spanDays.ToString()+"$"+ operateTime.ToString()+"$"+ latestSHZXTime.ToString()+"$"+ effectiveDate;



            }
            catch (Exception ex)
            {
                int a = 0;
            }
            return res;
        }


        /// <summary>
        /// 获取散货时效
        /// </summary>
        /// <returns></returns>
        public Hashtable getSHEffi(ArrayList arListLines,out bool isContainEffiDate)
        {
            isContainEffiDate = false;
            Hashtable htRes = new Hashtable();
            try
            {
                foreach (string strLine in arListLines)
                {
                    
                    SHTimeBean shBean = new SHTimeBean();
                    string[] arr = strLine.Split('$');
                    if (arr.Length < 6)
                    {
                        continue;
                    }
                    shBean.depNetworkName = arr[0];
                    shBean.arriveNetworkName = arr[1];
                    shBean.latestArrivalTime = arr[2];
                    shBean.plannedDepartureTime = arr[3];
                    shBean.plannedArrivalNextStiteTime = arr[4];

                    try
                    {
                        
                        shBean.spanDaysArrive = Convert.ToInt32(arr[5]);
                        shBean.spanDaysAssign = Convert.ToInt32(arr[6]);
                        shBean.dtEffi = Convert.ToDateTime(arr[7]);
                        isContainEffiDate = true;

                    }
                    catch (Exception ex)
                    {

                    }
                    if (!htRes.ContainsKey(shBean.depNetworkName))
                    {
                        htRes[shBean.depNetworkName] = new Hashtable();
                    }
                    Hashtable htNext = htRes[shBean.depNetworkName] as Hashtable;
                    if (!htNext.ContainsKey(shBean.arriveNetworkName))
                    {
                        htNext[shBean.arriveNetworkName] = new ArrayList();
                    }
                    ArrayList arListSHLines = htNext[shBean.arriveNetworkName] as ArrayList;
                    arListSHLines.Add(shBean);
                }

            }
            catch (Exception ex)
            {
                int a = 0;
            }
            return htRes;
        }


        /// <summary>
        /// 获取主线时效
        /// </summary>
        /// <returns></returns>
        public Hashtable getMainLineEffi(ArrayList arListLines,Hashtable htMainLineMap)
        {
            Hashtable htRes = new Hashtable();
            try
            {
                htMainLineMap.Clear();
                foreach (string strLine in arListLines)
                {
                    MainLineTimeBean mainLineBean = new MainLineTimeBean();
                    string[] arr = strLine.Split('$');
                    if (arr.Length < 6)
                    {
                        continue;
                    }
                    /*res = startCode.ToString() + "$" + endCode + "$" + startName.ToString() + "@" + endName.ToString() + "$" + startCode + "@" + endCode.ToString() + "$" + plannedDepartureTime.ToString() + "$" +
                       plannedArrivalTime.ToString() + "$" + spanDays.ToString();*/

                    if(strLine.Contains("保定") && strLine.Contains("西安"))
                    {
                        int a = 0;
                    }
                    string[] arrNames = arr[2].Split('@');
                    if (arrNames.Length < 2)
                    {
                        continue;
                    }

                    mainLineBean.startCode = arr[0];
                    mainLineBean.endCode = arr[1];
                    mainLineBean.startName = arrNames[0];
                    mainLineBean.endName = arrNames[1];
                    mainLineBean.sendAndNextName = arr[2];
                    mainLineBean.sendAndNextSite = arr[3];
                    mainLineBean.plannedDepartureTime = arr[4];
                    mainLineBean.plannedArrivalNextStopTime = arr[5];
                    try
                    {
             
                        mainLineBean.spanDaysArrive = Convert.ToInt32(arr[6]);
                        if(arr.Length>8)
                        {
                            mainLineBean.latestSHZXTime = arr[8];
                            mainLineBean.dtEffi = Convert.ToDateTime(arr[9]);
                        }
                        double hour = Convert.ToDouble(arr[7]) / 60;
                        if (StoParams.Instance.isUseOperationTime)
                        {
                            mainLineBean.operationHour = hour;
                        }
                        else
                        {
                            mainLineBean.operationHour = 1;
                        }
                        if(arr.Length>10)
                        {
                            mainLineBean.lineName = arr[10];
                            mainLineBean.jfyt = arr[11];
                        }
                    }
                    catch (Exception ex)
                    {

                    }
                    if (!htRes.ContainsKey(mainLineBean.startName))
                    {
                        htRes[mainLineBean.startName] = new Hashtable();
                    }
                    Hashtable htNext = htRes[mainLineBean.startName] as Hashtable;
                    if (!htNext.ContainsKey(mainLineBean.endName))
                    {
                        htNext[mainLineBean.endName] = new ArrayList();
                    }
                    ArrayList arListMainLines = htNext[mainLineBean.endName] as ArrayList;
                    arListMainLines.Add(mainLineBean);

                    string mainKey = mainLineBean.startName + "-" + mainLineBean.endName;
                    if(!htMainLineMap.ContainsKey(mainKey))
                    {
                        htMainLineMap[mainKey] = new ArrayList();
                    }
                    ArrayList arListLine = htMainLineMap[mainKey] as ArrayList;
                    arListLine.Add(mainLineBean);
                }

            }
            catch (Exception ex)
            {
                int a = 0;
            }
            return htRes;
        }

        public double getArrivaCenterAddHour(string priorCenter,string curCenter,string arrivalCurCenterTime)
        {
            double res = 0;
            try
            {
                if(!StoParams.Instance.isUseOperationTime)
                {
                    res = 1;
                }
                else
                {
                    if(LoadBasicHelper.Instance.m_ht_main_effi.ContainsKey(priorCenter))
                    {
                        string arrivalTime = arrivalCurCenterTime.Substring(arrivalCurCenterTime.Trim().IndexOf(' ') + 1);
                        arrivalTime = arrivalTime.Trim();
                        Hashtable htCenter = LoadBasicHelper.Instance.m_ht_main_effi[priorCenter] as Hashtable;
                        if(htCenter.ContainsKey(curCenter))
                        {
                            ArrayList arListCenters = htCenter[curCenter] as ArrayList;
                            foreach(MainLineTimeBean mainBean in arListCenters)
                            {
                                if (UtilityHelp.Instance.isBeanEffieLateThanCurSiteTime(arrivalCurCenterTime.ToString(), mainBean.dtEffi))
                                {
                                    continue;
                                }

                                if (Convert.ToDateTime(mainBean.plannedArrivalNextStopTime)>= Convert.ToDateTime(arrivalTime))
                                {
                                    res = mainBean.operationHour;
                                }
                            }
                        }
                    }
                }
            }
            catch(Exception ex)
            {

            }
            return res;
        }

        public ArrayList getDetailRoadMap(JArray detailList, ArrayList arListGXTask)
        {
            ArrayList arListRes = new ArrayList();
            arListGXTask = new ArrayList();
            try
            {
                
                for (int i = detailList.Count - 1; i >= 0; i--)
                {
                    JObject jobj = (JObject)detailList[i];
                    RoadBean roadBean = new bean.RoadBean();

                    JToken scanNetworkName = jobj["scanNetworkName"];
                    if (scanNetworkName != null)
                    {
                        roadBean.scanNetworkName = scanNetworkName.ToString();
                    }
                    JToken scanNetworkId = jobj["scanNetworkId"];
                    if (scanNetworkId != null)
                    {
                        roadBean.scanStieWorkID = scanNetworkId.ToString();
                    }

                    JToken weight = jobj["weight"];
                    if (weight != null)
                    {
                        roadBean.weight = weight.ToString();
                    }

                    

                    JToken scanNetworkTypeName = jobj["scanNetworkTypeName"];
                    if (scanNetworkTypeName != null)
                    {
                        roadBean.scanNetworkTypeName = scanNetworkTypeName.ToString();
                    }
                    JToken scanTypeName = jobj["scanTypeName"];
                    if (scanTypeName != null)
                    {
                        roadBean.scanTypeName = scanTypeName.ToString();
                        if (roadBean.scanTypeName.Contains("揽收"))
                        {
                            roadBean.lanshouSite = scanNetworkName.ToString();
                        }
                    }

                    JToken packageNumber = jobj["packageNumber"];
                    if (packageNumber != null)
                    {
                        roadBean.packageNumber = packageNumber.ToString();
                    }
                    

                    JToken nextNetworkCode = jobj["nextNetworkCode"];
                    if (nextNetworkCode != null)
                    {
                        roadBean.nextNetworkCode = nextNetworkCode.ToString();
                    }

                    JToken nextStopName = jobj["nextStopName"];
                    if (nextStopName != null)
                    {
                        roadBean.nextStopName = nextStopName.ToString();
                    }

                    JToken nextNetworkId = jobj["nextNetworkId"];
                    if (nextNetworkId != null)
                    {
                        roadBean.nextStopWorkID = nextNetworkId.ToString();
                    }

                    

                    JToken waybillTrackingContent = jobj["waybillTrackingContent"];
                    if (waybillTrackingContent != null)
                    {
                        roadBean.waybillTrackingContent = waybillTrackingContent.ToString();
                    }

                    JToken status = jobj["status"];
                    if (status != null)
                    {
                        roadBean.status = status.ToString();
                    }
                    JToken scanNetworkCode = jobj["scanNetworkCode"];
                    if (scanNetworkCode != null)
                    {
                        roadBean.scanNetworkCode = scanNetworkCode.ToString();
                    }
                    JToken actualArrivalTime = jobj["actualArrivalTime"];
                    if (actualArrivalTime != null)
                    {
                        roadBean.actualArrivalTime = actualArrivalTime.ToString();
                    }
                    JToken remark2 = jobj["remark2"];
                    if (remark2 != null && (remark2.ToString().Contains("GX")|| remark2.ToString().Contains("DKDD") || remark2.ToString().Contains("DBDD")))
                    {
                        roadBean.dkgx = remark2.ToString();
                        arListGXTask.Add(remark2.ToString());
                    }


                    if (scanTypeName != null && scanTypeName.ToString().Contains("出仓扫描")&& roadBean.staffName=="")
                    {
                        
                        JToken staffName = jobj["staffName"];
                        if (staffName != null)
                        {
                            roadBean.staffName = staffName.ToString();
                        }

                    }


                    if (scanTypeName!=null&& scanTypeName.ToString().Contains("入库扫描")&& roadBean.wareHouseName=="")
                    {
                        if (remark2 != null)
                        {
                            roadBean.wareHouseName = remark2.ToString();
                            //roadBean.dkgx = remark2.ToString();

                        }
                        JToken scanByName = jobj["scanByName"];
                        if(scanByName!=null)
                        {
                            roadBean.staffName = scanByName.ToString();
                        }

                    }

                    if(scanNetworkName!=null&& nextStopName!=null)
                    {
                        if((scanNetworkName.ToString().Contains("转运")|| scanNetworkName.ToString().Contains("分拨"))&& (nextStopName.ToString().Contains("转运") || nextStopName.ToString().Contains("分拨")))
                        {
                            if (remark2 != null)
                            {
                                roadBean.dkgx = remark2.ToString();
                                if(!arListGXTask.Contains(roadBean.dkgx))
                                {
                                    arListGXTask.Add(roadBean.dkgx);
                                }
                            }
                            
                        }
                    }
                    if (scanTypeName != null)
                    {
                        if(scanTypeName.ToString().Contains("到件"))
                        {
                            if(remark2 != null)
                            {
                                if(arListGXTask.Contains(remark2.ToString()))
                                {
                                    roadBean.dkgx = remark2.ToString();
                                }
                            }

                        }
                    }


                    JToken scanTime = jobj["scanTime"];
                    if (scanTime != null)
                    {
                        roadBean.scanTime = scanTime.ToString();
                    }

                    JToken planDepTime = jobj["plannedDepartureTime"];
                    if (planDepTime != null)
                    {
                        roadBean.plannedDepTime = planDepTime.ToString();
                    }

                    JToken actualDepartureTime = jobj["actualDepartureTime"];
                    if (actualDepartureTime != null)
                    {
                        roadBean.actDepTime = actualDepartureTime.ToString();
                    }

                    JToken plannedArrivalTime = jobj["plannedArrivalTime"];
                    if (plannedArrivalTime != null)
                    {
                        roadBean.plannedArrivalTime = plannedArrivalTime.ToString();
                    }





                    //临时时间添加
                    /*string strDateimt = "2023-08-06 04:49:00";
                    if (Convert.ToDateTime(roadBean.scanTime)> Convert.ToDateTime(strDateimt))
                    {
                        continue;
                    }*/


                    arListRes.Add(roadBean);


                }
            }
            catch (Exception ex)
            {

            }
            return arListRes;
        }

        public string getPriorCenterSortWrong(string curSite, ArrayList arList)
        {
            string res = "";
            try
            {
                for (int i = arList.Count - 1; i > 0; i--)
                {
                    if (arList[i].ToString() != "" && arList[i].ToString() != curSite)
                    {
                        res = arList[i].ToString();
                        break;
                    }
                }

            }
            catch (Exception ex)
            {

            }
            return res;
        }



        public bool isCurSiteReturnToPrior(string curSite, string priorCenter,int curIndex,ArrayList arListRoadMap)
        {
            bool res = false;
            try
            {
                for (int i = curIndex; i < arListRoadMap.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    if(roadBean.scanNetworkName== priorCenter&& roadBean.scanTypeName.Contains("到件"))
                    {
                        res = true;
                        break;
                    }
                }

            }
            catch (Exception ex)
            {

            }
            return res;
        }








        public bool isTerminalSameWtihDispatch(ArrayList arList, int curLineIndex, int endIndex)
        {
            bool isTerminalSame = false;
            try
            {
                string nextStopSite = "";
                string priorSendSiteTime = "";
                
                for (int i = curLineIndex-1; i <= arList.Count-1; i++)
                {
                    RoadBean roadBean = (RoadBean)arList[i];
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string nextStopName = "";


                    if (scanType == "发件扫描"||scanType=="装车发件")
                    {
                        string nextStop = roadBean.nextStopName;
                        if(nextStop.Contains("网点"))
                        {
                            nextStopSite = nextStop;
                            priorSendSiteTime = roadBean.scanTime;
                        }
                    
                    }

                    if (scanType == "卸车扫描"|| scanType == "到件扫描" || scanType == "卸车到件")
                    {
                        string scanSite = roadBean.scanNetworkName;
                        if(scanSite== nextStopSite)
                        {
                            string arriValTime = roadBean.scanTime;
                            TimeSpan ts = Convert.ToDateTime(arriValTime) - Convert.ToDateTime(priorSendSiteTime);
                            if(ts.TotalMinutes<20)
                            {
                                isTerminalSame = true;
                                break;
                            }
                        }
                       

                    }
                }

            }
            catch (Exception ex)
            {

            }
            return isTerminalSame;
        }



        public bool isNextStopArrived(string priorSite, ArrayList arList, int curLineIndex, int endIndex)
        {
            bool isNextStopArrive = false;
            try
            {
                bool isPriroArrival = false;
                bool isPriorSend = false;
                for (int i = curLineIndex; i <= endIndex; i++)
                {
                    RoadBean roadBean = (RoadBean)arList[i];
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string nextStopName = "";


                    if (scanType == "到件扫描" || scanType == "卸车扫描" || scanType == "卸车到件")
                    {
                        if (roadBean.scanNetworkName != priorSite)
                        {
                            isNextStopArrive = true;
                            return isNextStopArrive;
                        }


                    }
                }

            }
            catch (Exception ex)
            {

            }
            return isNextStopArrive;
        }


        public bool isPriorSendSiteAppearAgain(string priorSite, ArrayList arList, int curLineIndex)
        {
            bool isAppreaAgain = false;
            try
            {
                bool isPriroArrival = false;
                bool isPriorSend = false;
                for (int i = curLineIndex; i < arList.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arList[i];
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string nextStopName = "";


                    if (scanType == "发件扫描"||scanType=="装车发件")
                    {
                        nextStopName = nextName;
                        if (priorSite == nextStopName)
                        {
                            isPriroArrival = true;
                        }
                        if (roadBean.scanNetworkName == priorSite)
                        {
                            isPriorSend = true;
                        }

                        if (isPriroArrival && isPriorSend)
                        {
                            isAppreaAgain = true;
                        }

                    }
                }

            }
            catch (Exception ex)
            {

            }
            return isAppreaAgain;
        }

        public bool isInterceptMore(out string firstInterceptSite, ArrayList arList, int curLineIndex)
        {
            bool isAppreaAgain = false;
            firstInterceptSite = "";
            try
            {
                bool isPriroArrival = false;
                bool isPriorSend = false;
                ArrayList arlistIntercepts = new ArrayList();
                string lastShouldInterCept = "";
                for (int i = 0; i < curLineIndex; i++)
                {
                    RoadBean roadBean = (RoadBean)arList[i];
                    string scanType = roadBean.scanTypeName;
                    string nextStopName = "";
                    if (scanType == "发件扫描"||scanType=="装车发件")
                    {
                        lastShouldInterCept = roadBean.nextStopName;
                    }
                }
                string transferSite = "";
                for (int i = curLineIndex; i < arList.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arList[i];
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string nextStopName = "";
                    if (scanType == "转寄登记")
                    {
                        transferSite = roadBean.scanNetworkName;
                        continue;
                    }


                    if (scanType == "拦截件扫描")
                    {
                        if (roadBean.scanNetworkName != lastShouldInterCept)
                        {
                            isAppreaAgain = true;
                            firstInterceptSite = lastShouldInterCept;
                        }

                    }
                }

            }
            catch (Exception ex)
            {

            }
            return isAppreaAgain;
        }

        public bool isNextStopArrived(ArrayList arList, int curLineIndex, string nextStopName)
        {
            bool res = false;
            try
            {
                bool hasArrivalSite = false;
                string firstArrivaSite = "";
                for (int i = curLineIndex; i < arList.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arList[i];
                    string scanType = roadBean.scanTypeName;

                    if (scanType == "中心到件" || scanType == "卸车扫描" && firstArrivaSite == "")
                    {
                        hasArrivalSite = true;
                        firstArrivaSite = roadBean.scanNetworkName;
                        break;
                    }
                }
                if (firstArrivaSite == nextStopName)
                {
                    res = true;
                }
            }
            catch (Exception ex)
            {

            }
            return res;

        }



        public bool isNextStopNotArrivalButAppearNext(ArrayList arList, out string dutySide)
        {
            bool isSortWrong = false;
            dutySide = "";
            //有问题，需要细化 JT2901836148345
            try
            {
                ArrayList arListRes = new ArrayList();
                foreach (string strLine in arList)
                {
                    arListRes.Add(strLine);
                    string[] arrReverse = strLine.Split('@');
                    string revers = arrReverse[1] + "@" + arrReverse[0];
                    if (arListRes.Contains(revers))
                    {
                        dutySide = arrReverse[1];
                        isSortWrong = true;
                        return isSortWrong;
                    }
                }
                arListRes.Clear();
                Hashtable htDesIndex = new Hashtable();
                int rowIndex = 0;
                foreach (string strLine in arList)
                {
                    string[] arrReverse = strLine.Split('@');
                    if (arrReverse[0].Contains(arrReverse[1])|| arrReverse[1].Contains(arrReverse[0]))
                    {
                        continue;
                    }
                    arListRes.Add(strLine);
                   
                    if (!htDesIndex.ContainsKey(arrReverse[1]))
                    {
                        htDesIndex[arrReverse[1]] = rowIndex;
                    }
                    else
                    {
                        int priorRow = Convert.ToInt32(htDesIndex[arrReverse[1]]);
                        if (rowIndex - priorRow > 1)
                        {
                            isSortWrong = true;
                            string priorLine = arList[priorRow].ToString();
                            string[] arrs = priorLine.Split('@');
                            dutySide = arrs[0];
                            int middleIndex = priorRow + 1;
                            string middleLine = arList[middleIndex].ToString();
                            isSortWrong = true;
                            if (middleLine.Contains(arrs[0]) && middleLine.Contains(arrReverse[0]))
                            {
                                isSortWrong = false;
                            }
                           
                        }
                    }
                    rowIndex++;
                }

            }
            catch (Exception ex)
            {

            }
            Hashtable ht = new Hashtable();
            foreach(string strLine in arList)
            {
                string[] arrReverse = strLine.Split('@');
                if(arrReverse.Length>1)
                {
                    if(!ht.ContainsKey(arrReverse[1]))
                    {
                        ht[arrReverse[1]] = 1;
                    }
                    else
                    {
                        ht[arrReverse[1]] = Convert.ToInt32(ht[arrReverse[1]])+1;
                    }
                }
            }
            int max = 0;
            string maxSite = "";
            
            foreach(DictionaryEntry de in ht)
            {
                if(Convert.ToInt32(de.Value)> max)
                {
                    max = Convert.ToInt32(de.Value);
                    dutySide = de.Key.ToString();
                }
            }
            return isSortWrong;
        }

        public bool isReturnProblemParcel(string ori_addr)
        {
            bool res = false;
            try
            {
                if (ori_addr.Contains("退转问题件") && ori_addr.Trim().Length < 7)
                {

                    res = true;
                }

            }
            catch (Exception ex)
            {

            }
            return res;
        }

        public bool isNextStopSortWrong(ArrayList arList, int curLineIndex, string scanSiteName, string nextStopName,ArrayList arListSite)
        {
            bool isSortWrong = false;
            try
            {
                bool isPriroArrival = false;
                bool isPriorSend = false;
                ArrayList arlistIntercepts = new ArrayList();
                string lastShouldInterCept = "";
                bool hasArrivalSite = false;
                bool hasDepRecord = false;
                string firstArrivaSite = "";
                string firstDepDest = "";
                int endIndex = 0;
                for (int i = curLineIndex; i < arList.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arList[i];
                    string scanType = roadBean.scanTypeName;

                    if ((scanType == "到件扫描" || scanType == "卸车扫描" || scanType == "卸车到件") &&firstArrivaSite=="")
                    {
                        hasArrivalSite = true;
                        firstArrivaSite = roadBean.scanNetworkName;
                    }
                    if (scanType == "发件扫描" && firstDepDest == "")
                    {
                        firstDepDest = roadBean.nextStopName;
                        hasDepRecord = true;
                        endIndex = i;
                    }
                    if ((scanType == "发件扫描" || scanType == "装车发件") && roadBean.scanNetworkName.Length>1&& !arListSite.Contains(roadBean.scanNetworkName))
                    {
                        arListSite.Add(roadBean.scanNetworkName);
                    }

                    if (hasArrivalSite && hasDepRecord)
                    {
                        break;
                    }
                }
                string firstDepTemp = "";
                bool isYitiMachineSort = false;//是否一体机操作
                isYitiMachineSort = isScaleAndScanMachineSort(curLineIndex, arList, nextStopName);

                /*for (int i = curLineIndex; i < arList.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arList[i];
                    string scanType = roadBean.scanTypeName;

                    if (scanType == "到件扫描"&&!hasArrivalSite)
                    {
                        hasArrivalSite = true;
                        firstArrivaSite = roadBean.scanNetworkName;
                    }
                    if (scanType == "发件扫描" && firstDepTemp == "")
                    {
                        firstDepTemp = roadBean.nextStopName;
                        if(firstDepTemp== nextStopName&& roadBean.scanNetworkName== firstArrivaSite&& nextStopName.Contains("网点"))
                        {
                            isYitiMachineSort = true;
                            break;
                        }
                    }

                }*/
                //isYitiMachineSort = true;

                if (nextStopName == firstDepDest && firstArrivaSite != nextStopName && !isYitiMachineSort)
                {
                    if (isHasAnotherStopBeforeNextStopArrival(curLineIndex, endIndex, nextStopName, scanSiteName, arList))
                    {
                        isSortWrong = true;
                    }

                }


            }
            catch (Exception ex)
            {

            }
            return isSortWrong;
        }

        public bool isHasAnotherStopBeforeNextStopArrival(int curLineIndex, int endIndex, string nextStop, string dutySite, ArrayList arList)
        {
            bool res = false;
            try
            {

                for (int i = curLineIndex; i <= endIndex; i++)
                {
                    RoadBean roadBean = (RoadBean)arList[i];
                    string scanType = roadBean.scanTypeName;
                    if ((scanType == "中心到件" || scanType == "卸车扫描") && roadBean.scanNetworkName != dutySite && roadBean.scanNetworkName != nextStop)
                    {
                        res = true;
                        return res;
                    }

                }
            }
            catch (Exception ex)
            {

            }
            return res;
        }

        public bool isScaleAndScanMachineSort(int curLineIndex, ArrayList arList, string nextStopName)
        {
            bool isYitiMachineSort = false;//是否一体机操作
            try
            {


                bool hasArrivalSite = false;
                bool hasDepRecord = false;
                string firstArrivaSite = "";
                string firstDepDest = "";
                string firstDepTemp = "";
                for (int i = curLineIndex; i < arList.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arList[i];
                    string scanType = roadBean.scanTypeName;

                    if ((scanType == "到件扫描"|| scanType == "卸车到件") && !hasArrivalSite)
                    {
                        hasArrivalSite = true;
                        firstArrivaSite = roadBean.scanNetworkName;
                    }
                    if ((scanType == "发件扫描"|| scanType == "装车发件") && firstDepTemp == "")
                    {
                        firstDepTemp = roadBean.nextStopName;
                        if (firstDepTemp == nextStopName && roadBean.scanNetworkName == firstArrivaSite && nextStopName.Contains("网点"))
                        {
                            isYitiMachineSort = true;
                            break;
                        }
                    }

                }
            }
            catch (Exception ex)
            {

            }
            return isYitiMachineSort;

        }


        public bool isNoNeedContinueProblem(RoadBean roadBean )
        {
            bool res = true;
            try
            {
                if (roadBean.waybillTrackingContent.Contains("无理由拒收") || roadBean.waybillTrackingContent.Contains("地址信息")
                            || roadBean.waybillTrackingContent.Contains("取消") || roadBean.waybillTrackingContent.Contains("电话号码或联系人错误")
                           || roadBean.waybillTrackingContent.Contains("途中遗失")
                            || roadBean.waybillTrackingContent.Contains("有单无货") || roadBean.waybillTrackingContent.Contains("地址信息错误")
                            || roadBean.waybillTrackingContent.Contains("一货") || roadBean.waybillTrackingContent.Contains("转第三方")
                            || roadBean.waybillTrackingContent.Contains("抬头错") || roadBean.waybillTrackingContent.Contains("刷单")
                            || roadBean.waybillTrackingContent.Contains("外包装变形") || roadBean.waybillTrackingContent.Contains("电子运单模板")
                            || roadBean.waybillTrackingContent.Contains("运单信息不全") || roadBean.waybillTrackingContent.Contains("客户拒收")
                         )
                {
                    res = false;
                }
            }
            catch(Exception ex)
            {

            }
            return res;
        }

        public bool isTimeInDifferentDays(DateTime dt1, DateTime dt2)
        {
            bool res = false;
            try
            {
                if (dt1.ToShortDateString() != dt2.ToShortDateString())
                {
                    res = true;
                }
            }
            catch (Exception ex)
            {

            }
            return res;
        }


        public void getFirstPlanArrialTime(DateTime actDepToJSTime, ArrayList arListEffi, out string firstPlanArrivalTime)
        {
            string resTime = "";
            int addDays = 0;
            firstPlanArrivalTime = "";
            try
            {
                string time = actDepToJSTime.ToShortTimeString();
                TimeSpan ts = new TimeSpan();
                string notBingoTime = "";
                string notBingoPlanTime = "";
                bool isTimeLate = true;
                SHTimeBean shBeanTmp = new SHTimeBean();
                DateTime dtShortDate = actDepToJSTime.Date;
                foreach (SHTimeBean shBean in arListEffi)
                {
                    if (UtilityHelp.Instance.isBeanEffieLateThanCurSiteTime(actDepToJSTime.ToString(), shBean.dtEffi))
                    {
                        continue;
                    }

                    if (Convert.ToDateTime(time) < Convert.ToDateTime(shBean.plannedDepartureTime))
                    {
                        isTimeLate = false;
                        if (ts.TotalMinutes == 0)
                        {
                            ts = Convert.ToDateTime(shBean.plannedDepartureTime) - Convert.ToDateTime(time);
                            int addDaysTmp = 0;       

                           
                            if (Convert.ToDateTime(shBean.plannedArrivalNextStiteTime) < Convert.ToDateTime(shBean.plannedDepartureTime))
                            {
                                addDaysTmp = 1;
                            }
                            firstPlanArrivalTime = dtShortDate.AddDays(addDaysTmp).ToShortDateString() + " " + shBean.plannedArrivalNextStiteTime;
                            //addDays = shBean.spanDaysArrive;
                        }
                        else
                        {
                            TimeSpan tmp = Convert.ToDateTime(shBean.plannedDepartureTime) - Convert.ToDateTime(time);
                            if (tmp.TotalHours < ts.TotalHours)
                            {
                                resTime = shBean.plannedDepartureTime;
                                int addDaysTmp = 0;                       
                                if (Convert.ToDateTime(shBean.plannedArrivalNextStiteTime) < Convert.ToDateTime(shBean.plannedDepartureTime))
                                {
                                    addDaysTmp = 1;
                                }
                                firstPlanArrivalTime = dtShortDate.AddDays(addDaysTmp).ToShortDateString() + " " + shBean.plannedArrivalNextStiteTime;
                                //addDays = shBean.spanDaysArrive;
                                ts = tmp;
                            }
                        }
                    }
                    else
                    {
                        if (notBingoTime == "")
                        {
                            notBingoTime = shBean.plannedDepartureTime;
                            shBeanTmp = shBean;
                            if (notBingoPlanTime == "")
                            {
                                notBingoPlanTime = shBean.plannedArrivalNextStiteTime;
                            }

                        }
                        else
                        {
                            if (Convert.ToDateTime(notBingoTime) < Convert.ToDateTime(shBean.plannedDepartureTime))
                            {
                                notBingoTime = shBean.plannedDepartureTime;
                                shBeanTmp = shBean;
                                if (Convert.ToDateTime(notBingoPlanTime) < Convert.ToDateTime(shBean.plannedDepartureTime))
                                {
                                    notBingoPlanTime = shBean.plannedDepartureTime;
                                }


                            }
                        }


                    }
                }
                if (isTimeLate)
                {
                    addDays = 1;
                    resTime = notBingoTime;
                    firstPlanArrivalTime = notBingoPlanTime;
                    DateTime dtDate = Convert.ToDateTime(actDepToJSTime.ToShortDateString()).AddDays(addDays);
                    firstPlanArrivalTime = dtDate.ToShortDateString() + " " + firstPlanArrivalTime;
                }



            }
            catch (Exception ex)
            {

            }


        }


        public string getFirstPlanDepTimeUsingScanTime(DateTime jsActDepTime, ArrayList arListEffi, out string firstPlanArrivalTime,out bool isAssignAddDays)
        {
            string resTime = "";
            int addDays = 0;
            firstPlanArrivalTime = "";
            isAssignAddDays = false;


            try
            {
                string time = jsActDepTime.ToShortTimeString();
                TimeSpan ts = new TimeSpan();
                string notBingoTime = "";
                string notBingoPlanTime = "";
                bool isTimeLate = true;
                SHTimeBean shBeanTmp = new SHTimeBean();
                DateTime dtShortDate = jsActDepTime.Date;
                foreach (SHTimeBean shBean in arListEffi)
                {
                    if (UtilityHelp.Instance.isBeanEffieLateThanCurSiteTime(jsActDepTime.ToString(), shBean.dtEffi))
                    {
                        continue;
                    }

                    if (Convert.ToDateTime(time) < Convert.ToDateTime(shBean.plannedDepartureTime))
                    {
                        isTimeLate = false;
                        if (ts.TotalMinutes == 0)
                        {
                            ts = Convert.ToDateTime(shBean.plannedDepartureTime) - Convert.ToDateTime(time);
                            int addDaysTmp = 0;
                            /*if (Convert.ToDateTime(shBean.plannedDepartureTime) < Convert.ToDateTime(shBean.latestArrivalTime))
                            {
                                addDaysTmp = 1;
                            }*/

                            resTime = dtShortDate.AddDays(addDaysTmp).ToShortDateString() + " " + shBean.latestArrivalTime;
                            if (Convert.ToDateTime(shBean.plannedArrivalNextStiteTime) < Convert.ToDateTime(shBean.plannedDepartureTime))
                            {
                                addDaysTmp = 1;
                            }
                            if(shBean.spanDaysAssign>0)
                            {
                                isAssignAddDays = true;
                            }
                            firstPlanArrivalTime = dtShortDate.AddDays(addDaysTmp).ToShortDateString() + " " + shBean.plannedArrivalNextStiteTime;
                            //addDays = shBean.spanDaysArrive;
                        }
                        else
                        {
                            TimeSpan tmp = Convert.ToDateTime(shBean.plannedDepartureTime) - Convert.ToDateTime(time);
                            if (tmp.TotalHours < ts.TotalHours)
                            {
                                resTime = shBean.plannedDepartureTime;
                                int addDaysTmp = 0;
                                /*if (Convert.ToDateTime(shBean.plannedDepartureTime) < Convert.ToDateTime(shBean.latestArrivalTime))
                                {
                                    addDaysTmp = 1;
                                }*/
                                resTime = dtShortDate.AddDays(addDaysTmp).ToShortDateString() + " " + shBean.latestArrivalTime;
                                if (Convert.ToDateTime(shBean.plannedArrivalNextStiteTime) < Convert.ToDateTime(shBean.plannedDepartureTime))
                                {
                                    addDaysTmp = 1;
                                }
                                firstPlanArrivalTime = dtShortDate.AddDays(addDaysTmp).ToShortDateString() + " " + shBean.plannedArrivalNextStiteTime;
                                //addDays = shBean.spanDaysArrive;
                                ts = tmp;
                                if (shBean.spanDaysAssign > 0)
                                {
                                    isAssignAddDays = true;
                                }
                            }
                        }
                    }
                    else
                    {
                        if (notBingoTime == "")
                        {
                            notBingoTime = shBean.plannedDepartureTime;
                            shBeanTmp = shBean;
                            if (notBingoPlanTime == "")
                            {
                                notBingoPlanTime = shBean.plannedArrivalNextStiteTime;
                            }

                            if (shBean.spanDaysAssign > 0)
                            {
                                isAssignAddDays = true;
                            }

                        }
                        else
                        {
                            if (Convert.ToDateTime(notBingoTime) < Convert.ToDateTime(shBean.plannedDepartureTime) && shBean.spanDaysArrive == 0)
                            {
                                notBingoTime = shBean.plannedDepartureTime;
                                shBeanTmp = shBean;
                                if (Convert.ToDateTime(notBingoPlanTime) < Convert.ToDateTime(shBean.plannedDepartureTime))
                                {
                                    notBingoPlanTime = shBean.plannedDepartureTime;
                                }
                                if (shBean.spanDaysAssign > 0)
                                {
                                    isAssignAddDays = true;
                                }

                            }
                        }


                    }
                }
                if (isTimeLate)
                {
                    addDays = 1;
                    resTime = notBingoTime;
                    firstPlanArrivalTime = notBingoPlanTime;
                    DateTime dtDate = Convert.ToDateTime(jsActDepTime.ToShortDateString()).AddDays(addDays);
                    resTime = dtDate.ToShortDateString() + " " + resTime;
                    firstPlanArrivalTime = dtDate.ToShortDateString() + " " + shBeanTmp.plannedArrivalNextStiteTime;
                    if (shBeanTmp.spanDaysAssign > 0)
                    {
                        isAssignAddDays = true;
                    }
                }



            }
            catch (Exception ex)
            {

            }

            return resTime;
        }


        public string getFirstPlanDepTime(DateTime planArrivalSiteTime, ArrayList arListEffi, out string firstPlanArrivalTime)
        {
            string resTime = "";
            int addDays = 0;
            firstPlanArrivalTime = "";
            try
            {
                string time = planArrivalSiteTime.ToShortTimeString();
                TimeSpan ts = new TimeSpan();
                string notBingoTime = "";
                string notBingoPlanTime = "";
                bool isTimeLate = true;
                SHTimeBean shBeanTmp = new SHTimeBean();
                DateTime dtShortDate = planArrivalSiteTime.Date;
                foreach (SHTimeBean shBean in arListEffi)
                {
                    if (UtilityHelp.Instance.isBeanEffieLateThanCurSiteTime(planArrivalSiteTime.ToString(), shBean.dtEffi))
                    {
                        continue;
                    }

                    if (Convert.ToDateTime(time) <= Convert.ToDateTime(shBean.latestArrivalTime))
                    {
                        isTimeLate = false;
                        ts = Convert.ToDateTime(shBean.latestArrivalTime) - Convert.ToDateTime(time);
                        if (ts.TotalMinutes >=0)
                        {
                            
                            int addDaysTmp = 0;
                            if (Convert.ToDateTime(shBean.plannedDepartureTime) < Convert.ToDateTime(shBean.latestArrivalTime))
                            {
                                addDaysTmp = 1;
                            }

                            //resTime = dtShortDate.AddDays(addDaysTmp).ToShortDateString() + " " + shBean.latestArrivalTime;
                            resTime = dtShortDate.AddDays(addDaysTmp).ToShortDateString() + " " + shBean.plannedDepartureTime;
                            if (Convert.ToDateTime(shBean.plannedArrivalNextStiteTime) < Convert.ToDateTime(shBean.latestArrivalTime))
                            {
                                addDaysTmp = 1;
                            }
                            firstPlanArrivalTime = dtShortDate.AddDays(addDaysTmp).ToShortDateString() + " " + shBean.plannedArrivalNextStiteTime;
                            //addDays = shBean.spanDaysArrive;
                        }
                        else
                        {
                            TimeSpan tmp = Convert.ToDateTime(shBean.latestArrivalTime) - Convert.ToDateTime(time);
                            if (tmp.TotalHours < ts.TotalHours)
                            {
                                resTime = shBean.plannedDepartureTime;
                                int addDaysTmp = 0;
                                if (Convert.ToDateTime(shBean.plannedDepartureTime) < Convert.ToDateTime(shBean.latestArrivalTime))
                                {
                                    addDaysTmp = 1;
                                }
                                resTime = dtShortDate.AddDays(addDaysTmp).ToShortDateString() + " " + shBean.latestArrivalTime;
                                if (Convert.ToDateTime(shBean.plannedArrivalNextStiteTime) < Convert.ToDateTime(shBean.latestArrivalTime))
                                {
                                    addDaysTmp = 1;
                                }
                                firstPlanArrivalTime = dtShortDate.AddDays(addDaysTmp).ToShortDateString() + " " + shBean.plannedArrivalNextStiteTime;
                                //addDays = shBean.spanDaysArrive;
                                ts = tmp;
                            }
                        }
                    }
                    else
                    {
                        if (notBingoTime == "")
                        {
                            notBingoTime = shBean.latestArrivalTime;
                            shBeanTmp = shBean;
                            if (notBingoPlanTime == "")
                            {
                                notBingoPlanTime = shBean.plannedArrivalNextStiteTime;
                            }

                        }
                        else
                        {
                            if (Convert.ToDateTime(notBingoTime) < Convert.ToDateTime(shBean.latestArrivalTime) && shBean.spanDaysArrive == 0)
                            {
                                notBingoTime = shBean.latestArrivalTime;
                                shBeanTmp = shBean;
                                if (Convert.ToDateTime(notBingoPlanTime) < Convert.ToDateTime(shBean.latestArrivalTime))
                                {
                                    notBingoPlanTime = shBean.latestArrivalTime;
                                }


                            }
                        }


                    }
                }
                if (isTimeLate)
                {
                    addDays = 1;
                    resTime = notBingoTime;
                    firstPlanArrivalTime = notBingoPlanTime;
                    DateTime dtDate = Convert.ToDateTime(planArrivalSiteTime.ToShortDateString()).AddDays(addDays);
                    resTime = dtDate.ToShortDateString() + " " + resTime;
                    firstPlanArrivalTime = dtDate.ToShortDateString() + " " + firstPlanArrivalTime;
                }



            }
            catch (Exception ex)
            {

            }

            return resTime;
        }


        public string getLastPlanDepTimeForDispatch(DateTime planArrivalDispatchSiteTime, ArrayList arListEffi,  out string lastPlanArrivalTime)
        {
            string resTime = "";
            int addDays = 0;
            lastPlanArrivalTime = "";
            try
            {
                string time = planArrivalDispatchSiteTime.ToShortTimeString();
                TimeSpan ts = new TimeSpan();
                string notBingoTime = "";
                string notBingoPlanTime = "";
                bool isTimeLate = true;
                SHTimeBean shBeanTmp = new SHTimeBean();
                DateTime dtShortDate = planArrivalDispatchSiteTime.Date;
                foreach (SHTimeBean shBean in arListEffi)
                {
                    if (UtilityHelp.Instance.isBeanEffieLateThanCurSiteTime(planArrivalDispatchSiteTime.ToString(), shBean.dtEffi))
                    {
                        continue;
                    }
                    if (Convert.ToDateTime(time) < Convert.ToDateTime(shBean.latestArrivalTime))
                    {
                        isTimeLate = false;
                        if (ts.TotalMinutes == 0)
                        {
                            ts = Convert.ToDateTime(shBean.latestArrivalTime) - Convert.ToDateTime(time);
                            int addDaysTmp = 0;
                            if (Convert.ToDateTime(shBean.plannedDepartureTime) < Convert.ToDateTime(shBean.latestArrivalTime))
                            {
                                addDaysTmp = 1;
                            }

                            resTime = dtShortDate.AddDays(addDaysTmp).ToShortDateString() + " " + shBean.latestArrivalTime;
                            if (Convert.ToDateTime(shBean.plannedArrivalNextStiteTime) < Convert.ToDateTime(shBean.latestArrivalTime))
                            {
                                addDaysTmp = 1;
                            }
                            lastPlanArrivalTime = dtShortDate.AddDays(addDaysTmp).ToShortDateString() + " " + shBean.plannedArrivalNextStiteTime;
                            //addDays = shBean.spanDaysArrive;
                        }
                        else
                        {
                            TimeSpan tmp = Convert.ToDateTime(shBean.latestArrivalTime) - Convert.ToDateTime(time);
                            if (tmp.TotalHours > ts.TotalHours)
                            {
                                resTime = shBean.plannedDepartureTime;
                                int addDaysTmp = 0;
                                if (Convert.ToDateTime(shBean.plannedDepartureTime) < Convert.ToDateTime(shBean.latestArrivalTime))
                                {
                                    addDaysTmp = 1;
                                }
                                resTime = dtShortDate.AddDays(addDaysTmp).ToShortDateString() + " " + shBean.latestArrivalTime;
                                if (Convert.ToDateTime(shBean.plannedArrivalNextStiteTime) < Convert.ToDateTime(shBean.latestArrivalTime))
                                {
                                    addDaysTmp = 1;
                                }
                                lastPlanArrivalTime = dtShortDate.AddDays(addDaysTmp).ToShortDateString() + " " + shBean.plannedArrivalNextStiteTime;
                                //addDays = shBean.spanDaysArrive;
                                ts = tmp;
                            }
                        }
                    }
                    else
                    {
                        if (notBingoTime == "")
                        {
                            notBingoTime = shBean.latestArrivalTime;
                            shBeanTmp = shBean;
                            if (notBingoPlanTime == "")
                            {
                                notBingoPlanTime = shBean.plannedArrivalNextStiteTime;
                            }

                        }
                        else
                        {
                            if (Convert.ToDateTime(notBingoTime) < Convert.ToDateTime(shBean.latestArrivalTime) && shBean.spanDaysArrive == 0)
                            {
                                notBingoTime = shBean.latestArrivalTime;
                                shBeanTmp = shBean;
                                if (Convert.ToDateTime(notBingoPlanTime) < Convert.ToDateTime(shBean.latestArrivalTime))
                                {
                                    notBingoPlanTime = shBean.latestArrivalTime;
                                }


                            }
                        }


                    }
                }
                if (isTimeLate)
                {
                    addDays = 1;
                    resTime = notBingoTime;
                    lastPlanArrivalTime = notBingoPlanTime;
                    DateTime dtDate = Convert.ToDateTime(planArrivalDispatchSiteTime.ToShortDateString()).AddDays(addDays);
                    resTime = dtDate.ToShortDateString() + " " + resTime;
                    lastPlanArrivalTime = dtDate.ToShortDateString() + " " + lastPlanArrivalTime;
                }



            }
            catch (Exception ex)
            {

            }

            return resTime;
        }


        public string getLastPlanDepTimeUsingScanTime(DateTime depScanTime, ArrayList arListEffi,  out string lastPlanArrivalTime,out string planDispatchTime)
        {
            string resTime = "";
            int addDays = 0;
            lastPlanArrivalTime = "";
            planDispatchTime = "";
            try
            {
                string time = depScanTime.ToShortTimeString();
                TimeSpan ts = new TimeSpan();
                string notBingoTime = "";
                string notBingoPlanTime = "";
                bool isTimeLate = true;
                SHTimeBean shBeanTmp = new SHTimeBean();
                DateTime dtShortDate = depScanTime.Date;
                foreach (SHTimeBean shBean in arListEffi)
                {
                    if (UtilityHelp.Instance.isBeanEffieLateThanCurSiteTime(depScanTime.ToString(), shBean.dtEffi))
                    {
                        continue;
                    }

                    //if (Convert.ToDateTime(time) < Convert.ToDateTime(shBean.latestArrivalTime)&& Convert.ToDateTime(shBean.plannedArrivalNextStiteTime)<=Convert.ToDateTime(lastDispatchSiteArrival))
                    if (Convert.ToDateTime(time) <= Convert.ToDateTime(shBean.plannedDepartureTime))
                    {
                        isTimeLate = false;
                        if (ts.TotalMinutes == 0)
                        {
                            ts = Convert.ToDateTime(shBean.plannedDepartureTime) - Convert.ToDateTime(time);

                            int addDaysTmp = 0;

                            resTime = dtShortDate.AddDays(addDaysTmp).ToShortDateString() + " " + shBean.plannedDepartureTime;

                            if (Convert.ToDateTime(shBean.plannedArrivalNextStiteTime) < Convert.ToDateTime(shBean.plannedDepartureTime))
                            {
                                addDaysTmp = 1;
                            }

                            lastPlanArrivalTime = dtShortDate.AddDays(addDaysTmp).ToShortDateString() + " " + shBean.plannedArrivalNextStiteTime;
                            //addDays = shBean.spanDaysArrive;
                            planDispatchTime = dtShortDate.AddDays(shBean.spanDaysAssign).ToShortDateString() + " " + shBean.plannedArrivalNextStiteTime;
                        }
                        else
                        {
                            TimeSpan tmp = Convert.ToDateTime(shBean.plannedDepartureTime) - Convert.ToDateTime(time);
                            //if (tmp.TotalHours > ts.TotalHours && Convert.ToDateTime(shBean.plannedArrivalNextStiteTime) <= Convert.ToDateTime(lastDispatchSiteArrival))
                            if (tmp.TotalHours > ts.TotalHours)
                            {
                                resTime = shBean.plannedDepartureTime;
                                int addDaysTmp = 0;
      
                                resTime = dtShortDate.AddDays(addDaysTmp).ToShortDateString() + " " + shBean.plannedDepartureTime;

                                if (Convert.ToDateTime(shBean.plannedArrivalNextStiteTime) < Convert.ToDateTime(shBean.plannedDepartureTime))
                                {
                                    addDaysTmp = 1;
                                }
                                lastPlanArrivalTime = dtShortDate.AddDays(addDaysTmp).ToShortDateString() + " " + shBean.plannedArrivalNextStiteTime;
                                //addDays = shBean.spanDaysArrive;
                                planDispatchTime = dtShortDate.AddDays(shBean.spanDaysAssign).ToShortDateString() + " " + shBean.plannedArrivalNextStiteTime;
                                ts = tmp;
                            }
                        }
                    }
                    else
                    {
                        if (notBingoTime == "")
                        {
                            notBingoTime = shBean.plannedDepartureTime;
                            shBeanTmp = shBean;
                            if (notBingoPlanTime == "")
                            {
                                notBingoPlanTime = shBean.plannedArrivalNextStiteTime;
                            }

                        }
                        else
                        {
                            if (Convert.ToDateTime(notBingoTime) < Convert.ToDateTime(shBean.plannedDepartureTime) && shBean.spanDaysArrive == 0)
                            {
                                notBingoTime = shBean.plannedDepartureTime;
                                shBeanTmp = shBean;
                                if (Convert.ToDateTime(notBingoPlanTime) < Convert.ToDateTime(shBean.plannedArrivalNextStiteTime))
                                {
                                    notBingoPlanTime = shBean.plannedArrivalNextStiteTime;
                                }


                            }
                        }


                    }
                }
                if (isTimeLate)
                {
                    addDays = 1;
                    resTime = notBingoTime;
                    lastPlanArrivalTime = notBingoPlanTime;
                    DateTime dtDate = Convert.ToDateTime(depScanTime.ToShortDateString()).AddDays(addDays);
                    resTime = dtDate.ToShortDateString() + " " + resTime;
                    lastPlanArrivalTime = dtDate.ToShortDateString() + " " + lastPlanArrivalTime;
                    planDispatchTime = dtShortDate.AddDays(shBeanTmp.spanDaysAssign).ToShortDateString() + " " + shBeanTmp.plannedArrivalNextStiteTime;
                }



            }
            catch (Exception ex)
            {

            }

            return resTime;
        }



        public string getLastPlanDepTime(DateTime planArrivalLastCenterTime, ArrayList arListEffi,string lastDispatchSiteArrival,out string lastPlanArrivalTime,out string planDispatchTime)
        {
            string resTime = "";
            int addDays = 0;
            lastPlanArrivalTime = "";
            planDispatchTime = "";
            try
            {
                string time = planArrivalLastCenterTime.ToShortTimeString();
                TimeSpan ts = new TimeSpan();
                string notBingoTime = "";
                string notBingoPlanTime = "";
                bool isTimeLate = true;
                SHTimeBean shBeanTmp = new SHTimeBean();
                DateTime dtShortDate = planArrivalLastCenterTime.Date;
                Hashtable htEffiTime = new Hashtable();
                
                foreach (SHTimeBean shBean in arListEffi)
                {
                    if (UtilityHelp.Instance.isBeanEffieLateThanCurSiteTime(planArrivalLastCenterTime.ToString(), shBean.dtEffi))
                    {
                        continue;
                    }

                    //if (Convert.ToDateTime(time) < Convert.ToDateTime(shBean.latestArrivalTime)&& Convert.ToDateTime(shBean.plannedArrivalNextStiteTime)<=Convert.ToDateTime(lastDispatchSiteArrival))
                    //if (Convert.ToDateTime(time) <= Convert.ToDateTime(shBean.latestArrivalTime))
                    if (Convert.ToDateTime(time) <= Convert.ToDateTime(shBean.latestArrivalTime)&& 
                        Convert.ToDateTime(shBean.plannedArrivalNextStiteTime) <= Convert.ToDateTime(lastDispatchSiteArrival)
                        &&(Convert.ToDateTime(shBean.latestArrivalTime)< Convert.ToDateTime(lastDispatchSiteArrival)))
                    {
                        isTimeLate = false;
                        if (ts.TotalMinutes == 0)
                        {
                            ts = Convert.ToDateTime(shBean.latestArrivalTime) - Convert.ToDateTime(time);

                            int addDaysTmp = 0;
                            if(Convert.ToDateTime(shBean.plannedDepartureTime) < Convert.ToDateTime(shBean.latestArrivalTime))
                            {
                                addDaysTmp = 1;
                            }
                            resTime = dtShortDate.AddDays(addDaysTmp).ToShortDateString() + " " + shBean.plannedDepartureTime;

                            if(Convert.ToDateTime(shBean.plannedArrivalNextStiteTime)< Convert.ToDateTime(shBean.latestArrivalTime))
                            {
                                addDaysTmp = 1;
                            }

                            lastPlanArrivalTime = dtShortDate.AddDays(addDaysTmp).ToShortDateString() + " " + shBean.plannedArrivalNextStiteTime;
                            htEffiTime[resTime] = lastPlanArrivalTime;



                            if (shBean.arriveNetworkName.Contains("网点"))
                            {
                                planDispatchTime = dtShortDate.AddDays(shBean.spanDaysAssign).ToShortDateString() + " " + shBean.plannedArrivalNextStiteTime;
                            }
                            
                            //addDays = shBean.spanDaysArrive;
                        }
                        else
                        {
                            TimeSpan tmp = Convert.ToDateTime(shBean.latestArrivalTime) - Convert.ToDateTime(time);
                            //if (tmp.TotalHours > ts.TotalHours && Convert.ToDateTime(shBean.plannedArrivalNextStiteTime) <= Convert.ToDateTime(lastDispatchSiteArrival))
                            if (tmp.TotalHours > ts.TotalHours)
                            {
                                resTime = shBean.plannedDepartureTime;
                                int addDaysTmp = 0;
                                if (Convert.ToDateTime(shBean.plannedDepartureTime) < Convert.ToDateTime(shBean.latestArrivalTime))
                                {
                                    addDaysTmp = 1;
                                }
                                resTime = dtShortDate.AddDays(addDaysTmp).ToShortDateString() + " " + shBean.plannedDepartureTime;

                                if (Convert.ToDateTime(shBean.plannedArrivalNextStiteTime) < Convert.ToDateTime(shBean.latestArrivalTime))
                                {
                                    addDaysTmp = 1;
                                }
                                lastPlanArrivalTime = dtShortDate.AddDays(addDaysTmp).ToShortDateString() + " " + shBean.plannedArrivalNextStiteTime;
                                //addDays = shBean.spanDaysArrive;
                                ts = tmp;
                                if (shBean.arriveNetworkName.Contains("网点"))
                                {
                                    planDispatchTime = dtShortDate.AddDays(shBean.spanDaysAssign).ToShortDateString() + " " + shBean.plannedArrivalNextStiteTime;
                                }
                                   
                            }
                        }
                    }
                    else
                    {
                        if (notBingoTime == "")
                        {
                            notBingoTime = shBean.plannedDepartureTime;
                            shBeanTmp = shBean;
                            if(notBingoPlanTime == "")
                            {
                                notBingoPlanTime = shBean.plannedArrivalNextStiteTime;
                            }
                            
                        }
                        else
                        {
                            //8.10号修改，末端延误
                            //if (Convert.ToDateTime(shBeanTmp.latestArrivalTime) > Convert.ToDateTime(shBean.latestArrivalTime))
                            if (Convert.ToDateTime(shBeanTmp.latestArrivalTime) < Convert.ToDateTime(shBean.latestArrivalTime))
                            {
                                notBingoTime = shBean.plannedDepartureTime;
                                shBeanTmp = shBean;
                                //if(Convert.ToDateTime(notBingoPlanTime) >Convert.ToDateTime(shBean.plannedArrivalNextStiteTime))
                                if (Convert.ToDateTime(notBingoPlanTime) < Convert.ToDateTime(shBean.plannedDepartureTime))
                                {
                                    notBingoPlanTime = shBean.plannedArrivalNextStiteTime;
                                }
                                

                            }
                        }


                    }
                }
                if (isTimeLate)
                {
                    addDays = 1;
                    resTime = notBingoTime;
                    lastPlanArrivalTime = notBingoPlanTime;
                    DateTime dtDate = Convert.ToDateTime(planArrivalLastCenterTime.ToShortDateString()).AddDays(addDays);
                    resTime = dtDate.ToShortDateString() + " " + resTime;
                    lastPlanArrivalTime= dtDate.ToShortDateString() + " " + lastPlanArrivalTime;
                    if(shBeanTmp.arriveNetworkName.Contains("网点"))
                    {
                        planDispatchTime = dtShortDate.AddDays(addDays).ToShortDateString() + " " + shBeanTmp.plannedArrivalNextStiteTime;
                        //planDispatchTime = dtShortDate.AddDays(shBeanTmp.spanDaysAssign).ToShortDateString() + " " + shBeanTmp.plannedArrivalNextStiteTime;
                    }
                    
                }

               

            }
            catch (Exception ex)
            {

            }

            return resTime;
        }



        public string getLastJisanPlanDepTime(DateTime planArrivalJisanTime, ArrayList arListEffi, out bool islateForAllPlan,out string lastArrivalTime,out string planDispatchTime)
        {
            string resTime = "";
            int addDays = 0;
            islateForAllPlan = false;
            lastArrivalTime = "";
            planDispatchTime = "";
            try
            {
                string time = planArrivalJisanTime.ToShortTimeString();
                TimeSpan ts = new TimeSpan();
                string notBingoTime = "";
                bool isTimeLate = true;
                SHTimeBean shBeanTmp = new SHTimeBean();
                DateTime dtShortDate = planArrivalJisanTime.Date;
                foreach (SHTimeBean shBean in arListEffi)
                {
                    if (UtilityHelp.Instance.isBeanEffieLateThanCurSiteTime(planArrivalJisanTime.ToString(), shBean.dtEffi))
                    {
                        continue;
                    }

                    if (Convert.ToDateTime(time) <= Convert.ToDateTime(shBean.latestArrivalTime))
                    {
                        isTimeLate = false;
                        ts = Convert.ToDateTime(shBean.latestArrivalTime) - Convert.ToDateTime(time);
                        if (ts.TotalMinutes >= 0)
                        {
                           
                            //resTime = shBean.plannedDepartureTime;
                            int addDaysTmp = 0;
                            if (Convert.ToDateTime(shBean.plannedDepartureTime) < Convert.ToDateTime(shBean.latestArrivalTime))
                            {
                                addDaysTmp = 1;
                            }
                            string  curBeanPlanDepTime = dtShortDate.AddDays(addDaysTmp).ToShortDateString() + " " + shBean.plannedDepartureTime;
                            bool isValidBean = false;
                            if (resTime == "")
                            {
                                resTime = curBeanPlanDepTime;
                                isValidBean = true;
                            }
                            else
                            {
                                TimeSpan tsTmp = Convert.ToDateTime(curBeanPlanDepTime) - Convert.ToDateTime(resTime);
                                if(tsTmp.TotalMinutes>0)
                                {
                                    resTime = curBeanPlanDepTime;
                                    isValidBean = true;
                                }
                            }
                            if(isValidBean)
                            {
                                planDispatchTime = dtShortDate.AddDays(shBean.spanDaysAssign).ToShortDateString() + " " + shBean.plannedArrivalNextStiteTime;
                                shBeanTmp = shBean;
                                lastArrivalTime = shBean.latestArrivalTime;
                            }
                            
                        }
                        else
                        {
                            TimeSpan tmp = Convert.ToDateTime(shBean.latestArrivalTime) - Convert.ToDateTime(time);
                            if (tmp.TotalHours > ts.TotalHours)
                            {
                                int addDaysTmp = 0;
                                if (Convert.ToDateTime(shBean.plannedDepartureTime) < Convert.ToDateTime(shBean.latestArrivalTime))
                                {
                                    addDaysTmp = 1;
                                }
                                resTime = dtShortDate.AddDays(addDaysTmp).ToShortDateString() + " " + shBean.plannedDepartureTime;
                                ts = tmp;
                                shBeanTmp = shBean;
                                planDispatchTime = dtShortDate.AddDays(shBean.spanDaysAssign).ToShortDateString() + " " + shBean.plannedArrivalNextStiteTime;
                                lastArrivalTime = shBean.latestArrivalTime;
                            }
                        }
                    }
                    else
                    {
                        if (notBingoTime == "")
                        {
                            notBingoTime = shBean.plannedDepartureTime;
                            shBeanTmp = shBean;
                            //lastArrivalTime = shBean.latestArrivalTime;
                        }
                        else
                        {
                            if (Convert.ToDateTime(notBingoTime) < Convert.ToDateTime(shBean.plannedDepartureTime) && shBean.spanDaysArrive == 0)
                            {
                                notBingoTime = shBean.plannedDepartureTime;
                                shBeanTmp = shBean;
                            }
                        }
                    }
                }
                if (isTimeLate)
                {
                    islateForAllPlan = true;
                    addDays = 1;
                    resTime = dtShortDate.AddDays(addDays).ToShortDateString() + " " + notBingoTime;
                    planDispatchTime = dtShortDate.AddDays(1).ToShortDateString() + " " + shBeanTmp.plannedArrivalNextStiteTime;
                }

                if(isTimeLate)
                {
                    
                    foreach (SHTimeBean shBean in arListEffi)
                    {
                        if (UtilityHelp.Instance.isBeanEffieLateThanCurSiteTime(planArrivalJisanTime.ToString(), shBean.dtEffi))
                        {
                            continue;
                        }

                        if (shBean.latestArrivalTime=="")
                        {
                            continue;
                        }
                        if(lastArrivalTime=="")
                        {
                            lastArrivalTime = shBean.latestArrivalTime;
                        }
                        else
                        {
                            if(Convert.ToDateTime(lastArrivalTime)<Convert.ToDateTime(shBean.latestArrivalTime))
                            {
                                lastArrivalTime = shBean.latestArrivalTime;
                            }
                        }
                    }
                }

                //DateTime dtDate = Convert.ToDateTime(planArrivalJisanTime.ToShortDateString()).AddDays(addDays);
                //resTime = dtDate.ToShortDateString() + " " + resTime;


            }
            catch (Exception ex)
            {

            }

            return resTime;
        }


        public bool isSortWrongSiteAndReturn(ArrayList arListDep,Hashtable htDep, ResultBean resultBean)
        {
            bool res = false;
            try
            {
                int curRowIndex = 0;
                foreach (string strLine in arListDep)
                {
                    curRowIndex++;
                    if (strLine.Contains("@"))
                    {
                        string[] arr = strLine.Split('@');
                        string newKey = arr[1] + "@" + arr[0];
                      
                        if (htDep.ContainsKey(newKey) && htDep.ContainsKey(strLine))
                        {
                            TimeSpan ts = Convert.ToDateTime(htDep[newKey].ToString()) - Convert.ToDateTime(htDep[strLine].ToString());
                            if (Math.Abs(ts.TotalHours) > 2)
                            {
                                string dutySite = "";
                                if(isContainSite(arListDep, curRowIndex+1, arr[0]))
                                {
                                    dutySite = arr[0];
                                    resultBean.sortErrorSite = arr[1];
                                }
                                else
                                {
                                    dutySite = arr[1];
                                    resultBean.sortErrorSite = arr[0];
                                }
                                /*if(arr[0].Contains("网点"))
                                {
                                    dutySite = arr[0];
                                }
                                else
                                {
                                    dutySite = arr[1];
                                }*/
                                resultBean.dutySite = dutySite;
                                resultBean.errorType = "错发";
                                resultBean.errorMsg = dutySite + " 错发";
                                res = true;
                                break;
                            }
                        }
                    }
                }
            }
            catch(Exception ex)
            {

            }
            
            return res;
        }

        public bool isContainSite(ArrayList arListSites,int rowIndex,string siteName)
        {
            bool res = false;
            try
            {
                for(int i= rowIndex;i< arListSites.Count;i++)
                {
                    if(arListSites[i].ToString().Contains(siteName))
                    {
                        res = true;
                        break;
                    }
                }
            }
            catch(Exception ex)
            {

            }
            return res;

        }


        public bool isSortToWrongSite(ArrayList arListAllRoadMap, string dispatchSite,string lanshousite,ResultBean resultBean)
        {
            bool res=false;
            try
            {
                bool isAssignAppear = false;
                string fjToOtherSite = "";
                int index = 0;
                string firstCenter = "";
                string dutySite = "";
                foreach(RoadBean roadBean in arListAllRoadMap)
                {
                    string status = roadBean.status;
                    string scanType = roadBean.scanTypeName;
                    string nextStopName = roadBean.nextStopName;
                    string scanTime = roadBean.scanTime;
                    string scanSite = roadBean.scanNetworkName;
                    if((scanSite.Contains("转运中心")|| scanSite.Contains("分拨")) && firstCenter=="")
                    {
                        firstCenter = scanSite;
                    }
                    if (scanType.Contains("发件")&& nextStopName.Contains("网点")&& nextStopName!= dispatchSite&& firstCenter!=scanSite&& nextStopName!= lanshousite)
                    {
                       
                        if(fjToOtherSite=="")
                        {
                            fjToOtherSite = scanTime;
                            dutySite = scanSite;
                        }
                    }

                    if (scanType.Contains("卸车扫描")|| scanType.Contains("到件"))
                    {
                        if(fjToOtherSite!=""&& dutySite== scanSite)
                        {
                            int hour = Convert.ToDateTime(fjToOtherSite).Hour;
                            if(hour<12)
                            {
                                TimeSpan ts = Convert.ToDateTime(scanTime) - Convert.ToDateTime(fjToOtherSite);
                                if(ts.TotalHours>3)
                                {
                                    string prior = "中心";
                                    if(dutySite.Contains("集散"))
                                    {
                                        prior = "集散";
                                    }
                                    resultBean.errorType = prior + "错发";
                                    resultBean.dutySite = dutySite;
                                    resultBean.errorMsg = dutySite + "错发";
                                    res = true;
                                    break;
                                }
                            }
                        }
                    }
                    index++;

                }

            }
            catch(Exception ex)
            {

            }
            return res;
        }


        public string getFirstArrivaTime(DateTime planArrivalTime, ArrayList arListEffi)
        {
            string resTime = "";
            int addDays = 0;
            try
            {
                string time = planArrivalTime.ToShortTimeString();
                TimeSpan ts = new TimeSpan();
                string notBingoTime = "";
                bool isTimeLate = true;
                foreach (SHTimeBean shBean in arListEffi)
                {
                    if (UtilityHelp.Instance.isBeanEffieLateThanCurSiteTime(planArrivalTime.ToString(), shBean.dtEffi))
                    {
                        continue;
                    }

                    if (Convert.ToDateTime(time) < Convert.ToDateTime(shBean.plannedDepartureTime))
                    {
                        isTimeLate = false;
                        if (ts.TotalMinutes == 0)
                        {
                            ts = Convert.ToDateTime(shBean.plannedDepartureTime) - Convert.ToDateTime(time);
                            resTime = shBean.plannedArrivalNextStiteTime;
                            addDays = shBean.spanDaysArrive;
                        }
                        else
                        {
                            TimeSpan tmp = Convert.ToDateTime(shBean.plannedDepartureTime) - Convert.ToDateTime(time);
                            if (tmp.TotalHours < ts.TotalHours)
                            {
                                resTime = shBean.plannedArrivalNextStiteTime;
                                addDays = shBean.spanDaysArrive;
                                ts = tmp;
                            }
                        }
                    }
                    else
                    {
                        notBingoTime = shBean.plannedDepartureTime;
                    }
                }
                if (isTimeLate)
                {
                    addDays = 1;
                    resTime = notBingoTime;
                }

                DateTime dtDate = Convert.ToDateTime(planArrivalTime.ToShortDateString()).AddDays(addDays);
                resTime = dtDate.ToShortDateString() + " " + resTime;

            }
            catch (Exception ex)
            {

            }

            return resTime;
        }


        public string getMostRecentArrivaTime(DateTime actualDepTime, ArrayList arListEffi)
        {
            string resTime = "";
            int addDays = 0;
            try
            {
                string time = actualDepTime.ToShortTimeString();
                TimeSpan ts=new TimeSpan();
                string notBingoTime = "";
                bool isTimeLate = true;
                foreach (SHTimeBean shBean in arListEffi)
                {
                    if (UtilityHelp.Instance.isBeanEffieLateThanCurSiteTime(actualDepTime.ToString(), shBean.dtEffi))
                    {
                        continue;
                    }

                    if (shBean.dtEffi>= actualDepTime)
                    {
                        continue;
                    }
                    if(Convert.ToDateTime(time)<Convert.ToDateTime(shBean.plannedDepartureTime))
                    {
                        isTimeLate = false;
                        if (ts.TotalMinutes==0)
                        {
                            ts = Convert.ToDateTime(shBean.plannedDepartureTime) - Convert.ToDateTime(time);
                            resTime = shBean.plannedArrivalNextStiteTime;
                            addDays = shBean.spanDaysArrive;
                        }
                        else
                        {
                            TimeSpan tmp= Convert.ToDateTime(shBean.plannedDepartureTime) - Convert.ToDateTime(time);
                            if(tmp.TotalHours< ts.TotalHours)
                            {
                                resTime = shBean.plannedArrivalNextStiteTime;
                                addDays = shBean.spanDaysArrive;
                                ts = tmp;
                            }
                        }
                    }
                    else
                    {
                        if(notBingoTime=="")
                        {
                            notBingoTime = shBean.plannedArrivalNextStiteTime;
                        }
                        
                    }
                }
                if (isTimeLate)
                {
                    addDays = 1;
                    resTime = notBingoTime;
                }

                DateTime dtDate = Convert.ToDateTime(actualDepTime.ToShortDateString()).AddDays(addDays);
                resTime = dtDate.ToShortDateString() + " " + resTime;
                if(Convert.ToDateTime(resTime)< actualDepTime)
                {
                    resTime = Convert.ToDateTime(resTime).AddDays(1).ToString();
                }

            }
            catch (Exception ex)
            {

            }
           
            return resTime;
        }



        public string getFirstCenterPlanDepTime(DateTime actArrivalCurCenterTime, ArrayList arListMainEffi,out string planArrivalNextSiteTime)
        {
            string resTime = "";
            int addDays = 0;
            planArrivalNextSiteTime = "";
            try
            {
                //string time = actArrivalCurCenterTime.ToShortTimeString();
                //到件时间加1小时操作时间做对比
                string time = actArrivalCurCenterTime.AddHours(1).ToShortTimeString();
                string dateTime = actArrivalCurCenterTime.AddHours(1).ToString();
                TimeSpan ts = new TimeSpan();
                string notBingoTime = "";
                bool isTimeLate = true;
                DateTime dateshort = Convert.ToDateTime(actArrivalCurCenterTime.ToShortDateString());
                if(Convert.ToDateTime(dateTime).ToShortDateString()!= dateshort.ToShortDateString())
                {
                    dateshort = dateshort.AddDays(1);
                }
                MainLineTimeBean shBeanTmp = new MainLineTimeBean();
                string notBingoPlanArrivalNextSiteTime = "";
                foreach (MainLineTimeBean mainLineBean in arListMainEffi)
                {
                    if (UtilityHelp.Instance.isBeanEffieLateThanCurSiteTime(actArrivalCurCenterTime.ToString(), mainLineBean.dtEffi))
                    {
                        continue;
                    }

                    if (Convert.ToDateTime(time) <= Convert.ToDateTime(mainLineBean.plannedDepartureTime))
                    {
                        isTimeLate = false;
                        if (resTime=="")
                        {
                            ts = Convert.ToDateTime(mainLineBean.plannedDepartureTime) - Convert.ToDateTime(time);
                            resTime = mainLineBean.plannedDepartureTime;
                            //addDays = mainLineBean.spanDaysArrive;
                            planArrivalNextSiteTime = mainLineBean.plannedArrivalNextStopTime;
                            planArrivalNextSiteTime = dateshort.AddDays(mainLineBean.spanDaysArrive).ToShortDateString() + " " + planArrivalNextSiteTime;
                        }
                        else
                        {
                            TimeSpan tmp = Convert.ToDateTime(mainLineBean.plannedDepartureTime) - Convert.ToDateTime(time);
                            if (tmp.TotalHours < ts.TotalHours)
                            {
                                resTime = mainLineBean.plannedDepartureTime;
                                //addDays = mainLineBean.spanDaysArrive;
                                ts = tmp;
                                planArrivalNextSiteTime = mainLineBean.plannedArrivalNextStopTime;
                                planArrivalNextSiteTime = dateshort.AddDays(mainLineBean.spanDaysArrive).ToShortDateString() + " " + planArrivalNextSiteTime;
                            }
                        }
                    }
                    else
                    {
                        if (notBingoTime == "")
                        {
                            notBingoTime = mainLineBean.plannedDepartureTime;
                            shBeanTmp = mainLineBean;
                            if (notBingoPlanArrivalNextSiteTime == "")
                            {
                                notBingoPlanArrivalNextSiteTime = dateshort.AddDays(mainLineBean.spanDaysArrive).ToShortDateString() + " " +shBeanTmp.plannedArrivalNextStopTime;
                            }
                            //planArrivalNextSiteTime = mainLineBean.plannedArrivalNextStopTime;
                        }
                        else
                        {
                            if (Convert.ToDateTime(notBingoTime) > Convert.ToDateTime(mainLineBean.plannedDepartureTime))
                            {
                                notBingoTime = mainLineBean.plannedDepartureTime;
                                notBingoPlanArrivalNextSiteTime = dateshort.AddDays(mainLineBean.spanDaysArrive).ToShortDateString() + " " + shBeanTmp.plannedArrivalNextStopTime;
                                //planArrivalNextSiteTime = mainLineBean.plannedArrivalNextStopTime;
                            }
                        }


                    }
                }
                if (isTimeLate)
                {
                    addDays = 1;
                    resTime = notBingoTime;
                    planArrivalNextSiteTime = notBingoPlanArrivalNextSiteTime;
                    planArrivalNextSiteTime = Convert.ToDateTime(planArrivalNextSiteTime).AddDays(1).ToString();
                }
               
                DateTime dtDate = Convert.ToDateTime(actArrivalCurCenterTime.ToShortDateString()).AddDays(addDays);
                resTime = dtDate.ToShortDateString() + " " + resTime;
                if(Convert.ToDateTime(resTime)< actArrivalCurCenterTime)
                {
                    resTime = Convert.ToDateTime(resTime).AddDays(1).ToString();
                }
                if(Convert.ToDateTime(planArrivalNextSiteTime)< actArrivalCurCenterTime)
                {
                    planArrivalNextSiteTime = Convert.ToDateTime(planArrivalNextSiteTime).AddDays(1).ToString();
                }

            }
            catch (Exception ex)
            {

            }

            return resTime;
        }




        public void getCenterPlanDepTimeByNextsiteArrivalTime(DateTime planArrivalNextCenterTime, ArrayList arListMainEffi, out string planDepCurCenterTime)
        {
            string resTime = "";
            int addDays = 0;
            planDepCurCenterTime = "";
            try
            {
                

                TimeSpan ts = new TimeSpan();
                string notBingoTime = "";
                bool isTimeLate = true;
                string time = planArrivalNextCenterTime.ToShortTimeString();
                int spanDays = 0;


                MainLineTimeBean shBeanTmp = new MainLineTimeBean();
                string notBingoPlanArrivalNextSiteTime = "";
                foreach (MainLineTimeBean mainLineBean in arListMainEffi)
                {
                    if (UtilityHelp.Instance.isBeanEffieLateThanCurSiteTime(planArrivalNextCenterTime.ToString(), mainLineBean.dtEffi))
                    {
                        continue;
                    }

                    if (Convert.ToDateTime(time) == Convert.ToDateTime(mainLineBean.plannedArrivalNextStopTime))
                    {
                        isTimeLate = false;
                        if (resTime == "")
                        {
                            ts = Convert.ToDateTime(mainLineBean.plannedDepartureTime) - Convert.ToDateTime(time);
                            resTime = mainLineBean.plannedDepartureTime;
                            //addDays = mainLineBean.spanDaysArrive;
                            planDepCurCenterTime = mainLineBean.plannedDepartureTime;
                            spanDays = mainLineBean.spanDaysArrive;
                            planDepCurCenterTime = planArrivalNextCenterTime.AddDays(0-mainLineBean.spanDaysArrive).ToShortDateString() + " " + planDepCurCenterTime;
                            break;
                        }
             
                    }
  
                }


       

            }
            catch (Exception ex)
            {

            }

            
        }


        public bool isTimeInDifferentDays(ArrayList arlistTimes)
        {
            bool res = false;
            try
            {
                string priorDate = "";
                foreach(string strTime in arlistTimes)
                {
                    string curD = strTime.Substring(0, strTime.IndexOf(' '));
                    if(priorDate=="")
                    {
                        priorDate = curD;
                    }
                    else
                    {
                        if(priorDate!= curD)
                        {
                            res = true;
                        }
                    }
                }
            }
            catch(Exception ex)
            {

            }
            return res;
        }

        private bool isDepTimeInTime(string strSiteName,string strDestSite, string depTime,string strDate)
        {
            bool res = false;
            try
            {
                if (LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(strSiteName))
                {
                    Hashtable htsiteMap = LoadBasicHelper.Instance.m_ht_sh_effi[strSiteName] as Hashtable;
                    if (htsiteMap.ContainsKey(strDestSite))
                    {
                        ArrayList arListEffi = htsiteMap[strDestSite] as ArrayList;
                        foreach(SHTimeBean shBean in arListEffi)
                        {
                            if (UtilityHelp.Instance.isBeanEffieLateThanCurSiteTime(depTime.ToString(), shBean.dtEffi))
                            {
                                continue;
                            }

                            string planDepTime = strDate + " " + shBean.plannedDepartureTime;
                            if(shBean.spanDaysArrive>0)
                            {
                                planDepTime = Convert.ToDateTime(planDepTime).AddDays(shBean.spanDaysArrive).ToString();
                            }
                            if(Convert.ToDateTime(depTime)< Convert.ToDateTime(planDepTime))
                            {
                                res = true;
                                break;
                            }
                        }

                    }

                }
            }
            catch(Exception ex)
            {

            }
            return res;


        }


        public string getMapedCenter(string centerName)
        {
            string res = centerName;
            if(res== "石家庄藁城转运中心"&&!LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(res))
            {
                res = "石家庄转运中心";
            }
            return res;

        }

        public string getNextSite(string curSite,ArrayList arListAllSite)
        {
            string nextSite = "";
            try
            {
                if(arListAllSite.Contains(curSite))
                {
                    int siteIndex = arListAllSite.LastIndexOf(curSite);
                    if(siteIndex< arListAllSite.Count-1)
                    {
                        nextSite = arListAllSite[siteIndex + 1].ToString();
                    }
                }
            }
            catch(Exception ex)
            {

            }
            return nextSite;
        }



        public bool canGetLastCarDep( string planArrivalSiteTime, string arrivalSiteName,string nextSiteName,out string lastArrivalTime,out string lastDepTime)
        {
            bool res = true;
            lastArrivalTime = "";
            lastDepTime = "";
            try
            {
                if(LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(arrivalSiteName))
                {
                    Hashtable htSite = LoadBasicHelper.Instance.m_ht_sh_effi[arrivalSiteName] as Hashtable;
                    if(htSite.ContainsKey(nextSiteName))
                    {
                        ArrayList arListPlans = htSite[nextSiteName] as ArrayList;
                        bool isLateForAllPlans = false;
                        string dispatchPlanTime = "";
                        lastDepTime=getLastJisanPlanDepTime(Convert.ToDateTime(planArrivalSiteTime), arListPlans, out isLateForAllPlans,out lastArrivalTime,out dispatchPlanTime);
                        if(isLateForAllPlans)
                        {
                            res = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                res = false;
            }
            return res;
        }



        public string  shouldDepToReachNextSite(string nextStopReachTime, string arrivalSiteName, string nextSiteName)
        {
            string resShouldDeTime = "";
            try
            {
                if (LoadBasicHelper.Instance.m_ht_main_effi.ContainsKey(arrivalSiteName))
                {
                    Hashtable htSite = LoadBasicHelper.Instance.m_ht_main_effi[arrivalSiteName] as Hashtable;
                    if (htSite.ContainsKey(nextSiteName))
                    {
                        ArrayList arListPlans = htSite[nextSiteName] as ArrayList;
                        bool isLateForAllPlans = false;

                        MainLineTimeBean mainBeanTmp = new MainLineTimeBean();
                        foreach (MainLineTimeBean mainBean in arListPlans)
                        {
                            if (UtilityHelp.Instance.isBeanEffieLateThanCurSiteTime(arrivalSiteName.ToString(), mainBean.dtEffi))
                            {
                                continue;
                            }
                            if (Convert.ToDateTime(mainBean.plannedArrivalNextStopTime) <Convert.ToDateTime(nextStopReachTime))
                            {
                                if(mainBeanTmp.plannedArrivalNextStopTime == "")
                                {
                                    mainBeanTmp = mainBean;
                                }
                                else
                                {
                                    if(Convert.ToDateTime(mainBean.plannedArrivalNextStopTime)>Convert.ToDateTime(mainBeanTmp.plannedArrivalNextStopTime))
                                    {
                                        mainBeanTmp = mainBean;
                                    }
                                }
                                
                            }
                           
                        }
                        if(mainBeanTmp.plannedArrivalNextStopTime!="")
                        {
                            resShouldDeTime = mainBeanTmp.plannedDepartureTime;
                        }

                 
                    }
                }
            }
            catch (Exception ex)
            {
               
            }
            return resShouldDeTime;
        }


        public string getLastDispatchSiteArrival(ArrayList arListEffi,string depTime)
        {
            string res = "";
            foreach(SHTimeBean shBean in arListEffi)
            {
                if (UtilityHelp.Instance.isBeanEffieLateThanCurSiteTime(depTime.ToString(), shBean.dtEffi))
                {
                    continue;
                }
          
                string time = shBean.latestArrivalTime;
         
                if (res=="")
                {
                    res = time;
                }
                else if(Convert.ToDateTime(shBean.latestArrivalTime)>Convert.ToDateTime(res))
                {
                    res = time;
                }
            }
            return res;
        }

        public string getLastDispatchSiteRealArrival(ArrayList arListEffi,string condTime)
        {
            string res = "";
            SHTimeBean shBeanTmp = new SHTimeBean();
            foreach (SHTimeBean shBean in arListEffi)
            {
                if (UtilityHelp.Instance.isBeanEffieLateThanCurSiteTime(condTime.ToString(), shBean.dtEffi))
                {
                    continue;
                }
                string time = shBean.latestArrivalTime;
                if (res == "")
                {
                    res = time;
                    shBeanTmp = shBean;
                }
                else if (Convert.ToDateTime(shBean.latestArrivalTime) > Convert.ToDateTime(res))
                {
                    res = time;
                    shBeanTmp = shBean;
                }
            }
            if(res!="")
            {
                res = shBeanTmp.plannedArrivalNextStiteTime;
            }
            return res;
        }



        public bool isTerminalSendNextLate(ResultBean resultBean, string planArrivalCur,string actArrivalCur,string actDepToNext,
            ArrayList arlistAllSite,Hashtable htSiteTime,string curSite,string nextSite,out string planArrivalNextSiteTime,string dispatchSiteArrival)
        {
            bool res = false;
            string terminalSite = "";
            planArrivalNextSiteTime = "";
            try
            {
                int indexCur = arlistAllSite.IndexOf(curSite);
                int indexNext = arlistAllSite.IndexOf(nextSite);
                if (curSite.Contains("集散"))
                {
                    if (Convert.ToDateTime(planArrivalCur) > Convert.ToDateTime(actArrivalCur))
                    {
                        planArrivalCur = actArrivalCur;
                    }
                }

                if (indexNext - indexCur == 1)
                {
                    if (indexNext < arlistAllSite.Count - 1)
                    {
                        terminalSite = arlistAllSite[indexNext + 1].ToString();
                    }
                }

                res = isTerminalDepLate(resultBean, planArrivalCur, actArrivalCur, actDepToNext, arlistAllSite, htSiteTime, curSite, nextSite, terminalSite, out planArrivalNextSiteTime, dispatchSiteArrival);
                if (!res)
                {
                    res = isTerminalArrivalLate(resultBean, htSiteTime, planArrivalNextSiteTime, curSite, nextSite);
                }
            }
            catch(Exception ex)
            {

            }
            
            return res;
        }

        public bool isTerminalArrivalLate(ResultBean resultBean,Hashtable htSiteTime,string planArrivalJSTime, string curSite, string nextSite)
        {
            bool res = false;
            try
            {
                string curSitePlanArriveTime = "";
                string curSiteActArriveTime = "";
                string curSiteActDepTime = "";

                string nextSiteActArriveTime = "";

                //判断是否晚到件导致延误
                DbgBean dbgBean = htSiteTime[curSite] as DbgBean;

                if (utility.Utility.isTimeRight(dbgBean.actualArrivalTime))
                {
                    curSiteActArriveTime = dbgBean.actualArrivalTime.ToString();
                }

                if (utility.Utility.isTimeRight(dbgBean.actualDepartureTime))
                {
                    curSiteActDepTime = dbgBean.actualDepartureTime.ToString();
                }
                dbgBean = htSiteTime[nextSite] as DbgBean;

                if (utility.Utility.isTimeRight(dbgBean.actualArrivalTime))
                {
                    nextSiteActArriveTime = dbgBean.actualArrivalTime.ToString();
                }


                //判断集散是否晚到，导致延误,根据上一站转运发集散的时间，推断集散最晚发到网点的时间，判断是否与网点的到件日期一致
                //DateTime dtShouldArrivalJS=getShouldArrivalJisanTime(planDepTimeToJS, arListJS2Dispatch)
                if (planArrivalJSTime != "")
                {
                    string latestTime = "";
                    bool isSameDay = false;
                    DateTime dtPlanArrivalJS = Convert.ToDateTime(planArrivalJSTime).Date;
                    DateTime dtSiteArrial = Convert.ToDateTime(nextSiteActArriveTime).Date;
                    string lastDepTime = "";
                    if (dtPlanArrivalJS == dtSiteArrial || dtPlanArrivalJS > dtSiteArrial)
                    {
                        isSameDay = true;
                    }
                    if (UtilityHelp.Instance.canGetLastCarDep(planArrivalJSTime, curSite, nextSite, out latestTime,out lastDepTime) && !isSameDay)
                    {
                        string shouldDep = planArrivalJSTime.Substring(0, planArrivalJSTime.IndexOf(' ')) + " " + latestTime;

                        if (Convert.ToDateTime(curSiteActDepTime) > Convert.ToDateTime(shouldDep))
                        {
                            res = true;
                            resultBean.dutySite = curSite;
                            resultBean.errorMsg = "-末端晚到件延误 " + nextSite;
                            resultBean.errorType = "-末端晚到件延误";
                        }

                    }
                }
            }
            catch(Exception ex)
            {

            }

            

            return res;
        }

        public bool isTerminalDepLate(ResultBean resultBean, string planArrivalCur, string actArrivalCur, string actDepToNext, ArrayList arlistAllSite, Hashtable htSiteTime, string curSite, string nextSite,string terminalSite,out string planArrivalNextSiteTime,string dispatchSiteArrival)
        {
            bool res = false;
            planArrivalNextSiteTime = "";
            try
            {
                if(terminalSite.Contains("网点")&&nextSite.Contains("网点"))
                {
                    return false;
                }
                string planDepTimeToJS = "";
                ArrayList arListJS2JS = new ArrayList();
                if (LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(curSite))
                {
                    Hashtable htsiteMap = LoadBasicHelper.Instance.m_ht_sh_effi[curSite] as Hashtable;
                    if (htsiteMap.ContainsKey(nextSite))
                    {
                        ArrayList arListEffi = htsiteMap[nextSite] as ArrayList;


                        if (LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(nextSite))
                        {
                            Hashtable htJSToJS = LoadBasicHelper.Instance.m_ht_sh_effi[nextSite] as Hashtable;
                            if (htJSToJS.ContainsKey(terminalSite))
                            {
                                arListJS2JS = htJSToJS[terminalSite] as ArrayList;
                            }
                        }
                        if (arListJS2JS.Count == 0)
                        {
                            arListJS2JS = LoadBasicHelper.Instance.getDispatchSite(terminalSite);
                        }

                        string siteLatestArrivalTime = UtilityHelp.Instance.getLastDispatchSiteArrival(arListJS2JS, planArrivalCur);

                        if (terminalSite==""&& arListJS2JS.Count == 0&&nextSite.Contains("网点"))
                        {
                            siteLatestArrivalTime = UtilityHelp.Instance.getLastDispatchSiteArrival(arListEffi, planArrivalCur);

                            //arListJS2JS = arListEffi;
                            planDepTimeToJS = UtilityHelp.Instance.getLastPlanDepTimeForDispatch(Convert.ToDateTime(planArrivalCur), arListEffi,out planArrivalNextSiteTime);
                        }
                        else
                        {
                            if (planArrivalCur != "")
                            {
                                planDepTimeToJS = UtilityHelp.Instance.getLastPlanDepTime(Convert.ToDateTime(planArrivalCur), arListEffi, siteLatestArrivalTime, out planArrivalNextSiteTime,out planArrivalNextSiteTime);
                            }
                        }
                        
                       

                        

                        if (planDepTimeToJS == "")
                        {
                            foreach (SHTimeBean shBean in arListEffi)
                            {
                                if (UtilityHelp.Instance.isBeanEffieLateThanCurSiteTime(planArrivalCur.ToString(), shBean.dtEffi))
                                {
                                    continue;
                                }
                                if (planDepTimeToJS == "")
                                {
                                    if (shBean.plannedDepartureTime != "")
                                    {
                                        planDepTimeToJS = shBean.plannedDepartureTime.ToString();
                                    }
                                    continue;

                                }
                                else
                                {
                                    if (shBean.plannedDepartureTime != "")
                                    {
                                        if (Convert.ToDateTime(shBean.plannedDepartureTime) > Convert.ToDateTime(planDepTimeToJS))
                                        {
                                            planDepTimeToJS = shBean.plannedDepartureTime;
                                        }
                                    }
                                }
                            }

                        }


                    }
                    else
                    {
                        int a = 0;
                    }

                    if (actDepToNext != "" && planDepTimeToJS != "")
                    {
                        if (Convert.ToDateTime(actDepToNext) > Convert.ToDateTime(planDepTimeToJS))
                        {
                            res = true;
                            resultBean.dutySite = curSite;
                            resultBean.errorMsg = "末端晚发" + nextSite;
                            resultBean.errorType = "末端中转延误";
                            if(nextSite.Contains("网点"))
                            {
                                if(dispatchSiteArrival!="")
                                {
                                    if(Convert.ToDateTime(dispatchSiteArrival).Date== Convert.ToDateTime(actDepToNext).Date)
                                    {
                                        res = false;
                                    }
                                }
                            }
                        }
                        else
                        {
                            

                        }
                    }
                }
            }
            catch(Exception ex)
            {

            }
            return res;
        }

        public bool isAssignInTime(string planDepTimeToNetSite, string actDispatchTime,string jsSite,string dispatchSite)
        {
            bool res = false;
            try
            {

            }
            catch(Exception ex)
            {

            }
            return res;
        }



        public bool isMistakeReport(string curStop,string nextStop,ArrayList arlistCenters)
        {
            bool isMistake = false;
            try
            {
                int indexCur = arlistCenters.IndexOf(curStop);
                int indexNext = arlistCenters.IndexOf(nextStop);
                if(indexNext- indexCur==1)
                {
                    isMistake = true;
                }
            }
            catch(Exception ex)
            {

            }
            return isMistake;
        }

        public bool isDateEarlyUsingEarlyRoute(string dispatchArrival,string planToArrivalLastCenter,
            string lastCenter,string jsSite,string dispatchSite,string actJSDepTime,string assignTime,out string planArrivalDispatchSiteUsingEarly)
        {
            planArrivalDispatchSiteUsingEarly = "";
            bool res = false;
            try
            {
                ArrayList arListEffi = new ArrayList();
                if(LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(lastCenter))
                {
                    Hashtable htLastCenter = LoadBasicHelper.Instance.m_ht_sh_effi[lastCenter] as Hashtable;
                    if(htLastCenter.ContainsKey(jsSite))
                    {
                        arListEffi = htLastCenter[jsSite] as ArrayList;
                    }
                }
                string planArrivalNextSite = "";
                string planDepTimeUsingMostRecent = this.getFirstPlanDepTime(Convert.ToDateTime(planToArrivalLastCenter), arListEffi, out planArrivalNextSite);

                string planArrivalDisPatchSite = "";

                ArrayList arListDispacthEffi = new ArrayList();
                if (LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(jsSite))
                {
                    Hashtable htJS = LoadBasicHelper.Instance.m_ht_sh_effi[jsSite] as Hashtable;
                    if (htJS.ContainsKey(dispatchSite))
                    {
                        arListDispacthEffi = htJS[dispatchSite] as ArrayList;
                    }
                }

                this.getFirstPlanDepTime(Convert.ToDateTime(planArrivalNextSite), arListDispacthEffi, out planArrivalDisPatchSite);
                planArrivalDispatchSiteUsingEarly = planArrivalDisPatchSite;
                string lastSiteArrival = this.getLastDispatchSiteRealArrival(arListDispacthEffi, planToArrivalLastCenter);

                string orinalPlanArrivalDispatch = "";
                bool isAssingAddDays = false;
                this.getFirstPlanDepTimeUsingScanTime(Convert.ToDateTime(actJSDepTime), arListDispacthEffi, out orinalPlanArrivalDispatch,out isAssingAddDays);
                if (planArrivalDisPatchSite!=""&&dispatchArrival!="")
                {
                    bool isHaveToAssignNextDay = false;
                    if(Convert.ToDateTime(assignTime).Date> Convert.ToDateTime(dispatchArrival).Date)
                    {
                        TimeSpan ts = Convert.ToDateTime(assignTime).Date - Convert.ToDateTime(dispatchArrival).Date;
                        if (Convert.ToDateTime(dispatchArrival).Hour>Convert.ToDateTime(lastSiteArrival).Hour && isAssingAddDays==false
                            && ts.Days==1)
                        {
                            isHaveToAssignNextDay = true;
                        }
                    }
                    //2022-02-8 暂时加这里看效果
                    if(Convert.ToDateTime(orinalPlanArrivalDispatch)> Convert.ToDateTime(dispatchArrival)&& Convert.ToDateTime(dispatchArrival).Hour < Convert.ToDateTime(lastSiteArrival).Hour)
                    {
                        orinalPlanArrivalDispatch = dispatchArrival;
                    }
                    if(Convert.ToDateTime(orinalPlanArrivalDispatch).Date> Convert.ToDateTime(planArrivalDisPatchSite).Date)
                    {
                        res = true;
                    }
                }

            }
            catch(Exception ex)
            {

            }
            return res;


        }



        /// <summary>
        /// 废弃
        /// </summary>
        /// <param name="strBarCode"></param>
        /// <param name="commentType"></param>
        /// <param name="isReturn"></param>
        /// <returns></returns>
        public bool addCommentNew(string strBarCode, string commentType,bool isReturn=false)
        {
            bool ret = false;
            try
            {
                string strUrl = "https://jmsgw.jtexpress.com.cn/sqsthird/leaveMessage/getReceiveNetwork?waybillNo=" + strBarCode.Trim();
                JObject jObj = new JObject();
                JArray jarry = new JArray();
                jarry.Add(strBarCode);

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string res = HttpClient.HttpUtil.Instance.QueryCommon(strUrl, postData, "GET", "integratedQuery");
                if (!res.Contains("请求成功"))
                {
                    if (res.Contains("msg"))
                    {
                        JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(res);
                        JToken msgToken = jsonObjRes["msg"];
                        StoParams.Instance.resMsg = msgToken.ToString();
                    }
                    else
                    {
                        StoParams.Instance.resMsg = res.ToString();
                    }
                    //QueryMessageRes.Invoke();
                    return ret;
                }
                string msg = "";
                ArrayList arListRoadMap = new ArrayList();
                ArrayList arListRoadGX = new ArrayList();
                arListRoadMap = JTDelayHelperNew.Instance.getRoadMap(strBarCode.Trim(), out msg, arListRoadGX);
                SiteBean siteBean = UtilityHelp.Instance.getFirstSite(res, arListRoadMap);
                //SiteBean siteBean = UtilityHelp.Instance.getLastSite(res);
                if (siteBean.siteCode == "")
                {
                    siteBean = UtilityHelp.Instance.getBeanSite(arListRoadMap);
                }
                if (siteBean.siteCode == "" && siteBean.siteId == "")
                {
                    return ret;
                }

                if (siteBean.siteCode == "" && siteBean.siteId != "")
                {
                    try
                    {
                        strUrl = "https://jmsgw.jtexpress.com.cn/operatingplatform/networkInfo/getNetworkDetailInfoById?networkId=" + siteBean.siteId.Trim();
                        jObj = new JObject();
                        jarry = new JArray();
                        jarry.Add(strBarCode);

                        postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                        res = HttpClient.HttpUtil.Instance.QueryCommon(strUrl, postData, "GET", "trackingExpress");
                        if (res.Contains("请求成功"))
                        {
                            if (res.Contains("data"))
                            {
                                JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(res);

                                JObject jsonObjData = (JObject)jsonObjRes["data"]; ;
                                JToken networkCode = jsonObjData["networkCode"];
                                siteBean.siteCode = networkCode.ToString();

                            }

                        }
                    }
                    catch (Exception ex)
                    {

                    }

                }

                if (StoParams.Instance.register_site.Contains(siteBean.siteName.Trim())
                    || siteBean.siteName.Trim().Contains(StoParams.Instance.register_site))
                {
                    //AddMessage.Invoke();
                    return ret;
                }
                jObj["waybillNo"] = strBarCode.Trim();
                jObj["receiveNetworkId"] = siteBean.siteId.Trim();
                jObj["fileUrl"] = "";
                jObj["receiveNetworkName"] = siteBean.siteName.Trim();
                jObj["receiveNetworkCode"] = siteBean.siteCode.Trim();
                jObj["countryId"] = "1";
                jObj["leaveMessageType"] = 4;
                string tmplete = MemberInfo.Instance.templeteTransfer;
                if (commentType.Contains("中转"))
                {
                    tmplete = MemberInfo.Instance.templeteTransfer;
                }
                else if (commentType.Contains("派件"))
                {
                    tmplete = MemberInfo.Instance.templeteAssign;
                }
                else if (commentType.Contains("签收"))
                {
                    tmplete = MemberInfo.Instance.templeteQS;
                }
                else if (commentType.Contains("拦截"))
                {
                    //tmplete = "此件已退款，商家急催要求尽快退回";
                    tmplete = MemberInfo.Instance.templeteReturn;
                }
                if(isReturn)
                {
                    tmplete = MemberInfo.Instance.templeteReturn;
                }
                jObj["replyContent"] = tmplete;
                //string postUrl = "https://jmsgw.jtexpress.com.cn/servicequality/leaveMessage/add";
                string postUrl = "https://jmsgw.jtexpress.com.cn/operatingplatform/messageBoard/add";
                postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);

                //return;
                string messge = HttpClient.HttpUtil.Instance.addLeaveMessage(postUrl, postData);
                if (messge.Contains("成功"))
                {
                    ret = true;
                    StoParams.Instance.resMsg = "留言成功";
                }
                else
                {
                    StoParams.Instance.resMsg =  "留言失败 "+ messge;
                }
                //QueryMessageRes.Invoke();
            }
            catch (Exception ex)
            {

            }
            return ret;
        }



        public bool addCommentReg(string strBarCode, string commentType, bool isIntercept = false,string addr="",string leaveMsg="")
        {
            bool ret = false;
            try
            {
                string strUrl = "https://jmsgw.jtexpress.com.cn/sqsthird/leaveMessage/getReceiveNetwork?waybillNo=" + strBarCode.Trim();
                JObject jObj = new JObject();
                JArray jarry = new JArray();
                jarry.Add(strBarCode);

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string res = HttpClient.HttpUtil.Instance.QueryCommon(strUrl, postData, "GET", "integratedQuery");
                if (!res.Contains("请求成功"))
                {
                    if (res.Contains("msg"))
                    {
                        JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(res);
                        JToken msgToken = jsonObjRes["msg"];
                        StoParams.Instance.resMsg = msgToken.ToString();
                    }
                    else
                    {
                        StoParams.Instance.resMsg = res.ToString();
                    }
                    //QueryMessageRes.Invoke();
                    return ret;
                }
                string msg = "";
                ArrayList arListRoadMap = new ArrayList();
                ArrayList arListRoadGX = new ArrayList();
                arListRoadMap = JTDelayHelperNew.Instance.getRoadMap(strBarCode.Trim(), out msg, arListRoadGX);
                SiteBean siteBean = UtilityHelp.Instance.getFirstSite(res, arListRoadMap);
                //SiteBean siteBean = UtilityHelp.Instance.getLastSite(res);
                if (siteBean.siteCode == "")
                {
                    siteBean = UtilityHelp.Instance.getBeanSite(arListRoadMap);
                }
                if (siteBean.siteCode == "" && siteBean.siteId == "")
                {
                    return ret;
                }

                if (siteBean.siteCode == "" && siteBean.siteId != "")
                {
                    try
                    {
                        strUrl = "https://jmsgw.jtexpress.com.cn/operatingplatform/networkInfo/getNetworkDetailInfoById?networkId=" + siteBean.siteId.Trim();
                        jObj = new JObject();
                        jarry = new JArray();
                        jarry.Add(strBarCode);

                        postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                        res = HttpClient.HttpUtil.Instance.QueryCommon(strUrl, postData, "GET", "trackingExpress");
                        if (res.Contains("请求成功"))
                        {
                            if (res.Contains("data"))
                            {
                                JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(res);

                                JObject jsonObjData = (JObject)jsonObjRes["data"]; ;
                                JToken networkCode = jsonObjData["networkCode"];
                                siteBean.siteCode = networkCode.ToString();

                            }

                        }
                    }
                    catch (Exception ex)
                    {

                    }

                }

                if (StoParams.Instance.register_site.Contains(siteBean.siteName.Trim())
                    || siteBean.siteName.Trim().Contains(StoParams.Instance.register_site))
                {
                    //AddMessage.Invoke();
                    return ret;
                }

                ProblemBean problemBean = getProblemBean(isIntercept);
                jObj["waybillNo"] = strBarCode.Trim();
                jObj["replyContent"] = "";
                jObj["problemPieceId"] = "";
                jObj["probleTypeSubjectId"] = problemBean.probleTypeSubjectId;
                jObj["probleTypeSubjectId2"] = problemBean.probleTypeSubjectId2;
                jObj["receiveNetworkId"] = siteBean.siteId.Trim();
                jObj["replyContentImg"] = new JArray() ;
                jObj["replyStatus"] = 0;
                jObj["probleTypeId"] = 1;
                jObj["uploadDataProp"] = "";
                jObj["knowNetwork"] = "";
                jObj["defaultKnow"] = null;
                jObj["firstLevelTypeName"] = problemBean.firstLevelTypeName;
                jObj["problemTypeSubjectCode"] = problemBean.problemTypeSubjectCode;
                jObj["secondLevelTypeId"] = problemBean.secondLevelTypeId;
                jObj["secondLevelTypeCode"] = problemBean.secondLevelTypeCode;
                jObj["secondLevelTypeName"] = problemBean.secondLevelTypeName;
                jObj["paths"] = "";
                jObj["countryId"] = "1";
                string tmplete = leaveMsg+" "+addr;
                if(leaveMsg.Trim()=="")
                {
                    if (commentType.Contains("中转"))
                    {
                        tmplete = MemberInfo.Instance.templeteTransfer + " " + addr;
                    }
                    else if (commentType.Contains("派件"))
                    {
                        tmplete = MemberInfo.Instance.templeteAssign + " " + addr;
                    }
                    else if (commentType.Contains("签收"))
                    {
                        tmplete = MemberInfo.Instance.templeteQS + " " + addr;
                    }
                    else if (commentType.Contains("拦截"))
                    {
                        tmplete = MemberInfo.Instance.templeteReturn + " " + addr;
                    }
                }
                /*if (commentType.Contains("中转"))
                {
                    tmplete = MemberInfo.Instance.templeteTransfer;
                }
                else if (commentType.Contains("派件"))
                {
                    tmplete = MemberInfo.Instance.templeteAssign;
                }
                else if (commentType.Contains("签收"))
                {
                    tmplete = MemberInfo.Instance.templeteQS;
                }
                else if (commentType.Contains("拦截"))
                {
                    tmplete = MemberInfo.Instance.templeteReturn;
                }*/
                if (isIntercept)
                {
                    tmplete = leaveMsg + " " + addr; ;
                }
                string msgLv = tmplete + " " + MemberInfo.Instance.templeteReturn;
                if(msgLv.Length>=100)
                {
                    msgLv = msgLv.Substring(0, 98);
                }

                jObj["probleDescription"] = msgLv;
                string postUrl = "https://jmsgw.jtexpress.com.cn/servicequality/problemPiece/registration";
                postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);

                //return;
                string messge = HttpClient.HttpUtil.Instance.PostCommon(postUrl, postData, "batchProblem");
                if (messge.Contains("成功"))
                {
                    ret = true;
                    StoParams.Instance.resMsg = "留言成功";
                }
                else
                {
                    StoParams.Instance.resMsg = "留言失败 " + messge;
                }
                //QueryMessageRes.Invoke();
            }
            catch (Exception ex)
            {

            }
            return ret;
        }


        public ProblemBean getProblemBean(bool isIntercept)
        {
            ProblemBean problemBean = new ProblemBean();
            if(isIntercept)
            {
                problemBean.probleTypeSubjectId = 120;
                problemBean.firstLevelTypeName = "异常拦截件";
                problemBean.problemTypeSubjectCode = "50";
                problemBean.probleTypeSubjectId2 = 100036;
                problemBean.secondLevelTypeId= 100036;
                problemBean.secondLevelTypeCode = "28a";
                problemBean.secondLevelTypeName = "异常拦截件a";


            }
            return problemBean;

        }

        public ArrayList getJtBarcode(string content)
        {
            ArrayList arListBarcodes = new ArrayList();
            try
            {
                //content = "JT3019637551824";
                while(content.IndexOf("JT")>=0)
                {
                    int JTIndex = content.IndexOf("JT");
                    string subStr = content.Substring(JTIndex, 15);
                    MatchCollection matchss = Regex.Matches(subStr, jtReg);
                    if(matchss.Count>0)
                    {
                        arListBarcodes.Add(subStr);
                    }
                    content = content.Replace(subStr, "");


                }
                /*MatchCollection matchs = Regex.Matches(content, jtReg);
                foreach(Match item in matchs)
                {
                    arListBarcodes.Add(item.Value);
                }*/
            }
            catch(Exception ex)
            {

            }
            return arListBarcodes;
        }


        public ArrayList getYTBarcode(string content)
        {
            ArrayList arListBarcodes = new ArrayList();
            try
            {
                //content = "JT3019637551824";
                while (content.IndexOf("YT") >= 0)
                {
                    int JTIndex = content.IndexOf("YT");
                    string subStr = content.Substring(JTIndex, 15);
                    MatchCollection matchss = Regex.Matches(subStr, YtReg);
                    if (matchss.Count > 0)
                    {
                        arListBarcodes.Add(subStr);
                    }
                    content = content.Replace(subStr, "");


                }
                /*MatchCollection matchs = Regex.Matches(content, jtReg);
                foreach(Match item in matchs)
                {
                    arListBarcodes.Add(item.Value);
                }*/
            }
            catch (Exception ex)
            {

            }
            return arListBarcodes;
        }


        public string removeHeaderText(string content)
        {
            string resContent = content;
            try
            {
                resContent = resContent.Replace("  ", " ");
                resContent = resContent.Replace("极兔快递（原百世快递）JT", "JT");
                resContent = resContent.Replace("极兔快递 JT", "JT");
                resContent = resContent.Replace("极兔快递,JT", "JT");
                resContent = resContent.Replace("极兔速递 JT", "JT");
                resContent = resContent.Replace("极兔速递,JT", "JT");
                resContent = resContent.Replace("极兔速递，JT", "JT");
            }
            catch(Exception ex)
            {

            }
            return resContent;
        }


        public bool isStoParcel(string content,TaskBean taskBean)
        {
            bool res = false;
            try
            {

                Hashtable htcus = new Hashtable();
                try
                {
                    string storegexStr = StoParams.Instance.storegexStr;
                    Regex stoRegex = new Regex(storegexStr);

                    //string[] arr = content.Split('\n');
                    ArrayList arr = getContinueParcelNumber(content);

                    ArrayList arListSto = new ArrayList();

                    foreach (string strLine in arr)
                    {

                        string[] tmpArr = strLine.Split(' ');
                        foreach (string val in tmpArr)
                        {
                            string valN = val;
                            string curV = val;
                            if (isContainChinese(val, out valN))
                            {
                                curV = valN;
                            }
                            if(curV.Length>=15)
                            {
                                curV = curV.Substring(0, 15);
                            }
                            if (curV.Length > 5 && stoRegex.IsMatch(curV))
                            {
                                arListSto.Add(curV);
                                if(!taskBean.arListWaybills.Contains(curV))
                                {
                                    taskBean.arListWaybills.Add(curV);
                                }
                               

                            }

                        }
                    }
                    if (arListSto.Count > 0)
                    {
                        res = true;
                    }

                }
                catch (Exception ex)
                {

                }






            }
            catch(Exception ex)
            {

            }
            return res;
        }


        public bool isEmsParcel(string content,TaskBean taskBean)
        {
            bool res = false;
            try
            {

                Hashtable htcus = new Hashtable();
                try
                {
                    string emsRegexStr = "^(9)[0-9]{12}$";
                    Regex emsRegex = new Regex(emsRegexStr);
                    
                    //string[] arr = content.Split('\n');
                    ArrayList arr = getContinueParcelNumber(content);

                    ArrayList arListEms = new ArrayList();

                    foreach (string strLine in arr)
                    {

                        string[] tmpArr = strLine.Split(' ');
                        foreach (string val in tmpArr)
                        {
                            string valN = val;
                            string curV = val;
                            if (isContainChinese(val, out valN))
                            {
                                curV = valN;
                            }
                            if (curV.Length >= 15)
                            {
                                curV = curV.Substring(0, 13);
                            }
                            if (curV.Length > 5 && emsRegex.IsMatch(curV))
                            {
                                arListEms.Add(curV);
                                if (!taskBean.arListWaybills.Contains(curV))
                                {
                                    taskBean.arListWaybills.Add(curV);
                                }
                         

                            }
                            else
                            {
                                if(curV.Length==13&& curV.StartsWith("1")&&MathUtility.ImpIsNum(curV))
                                {
                                    arListEms.Add(curV);
                                    if (!taskBean.arListWaybills.Contains(curV))
                                    {
                                        taskBean.arListWaybills.Add(curV);
                                    }
                                }
                            }


                        }
                    }
                    if (arListEms.Count > 0)
                    {
                        res = true;
                    }

                   

                }
                catch (Exception ex)
                {

                }






            }
            catch (Exception ex)
            {

            }
            return res;
        }


        public bool isZtoParcel(string content,TaskBean taskBean)
        {
            bool res = false;
            try
            {
                Hashtable htCustomer = new Hashtable();
                ArrayList arListZto = new ArrayList();
               
                string ztoRegexStr = StoParams.Instance.ztoRegexStr;
                Regex ztoRegex = new Regex(ztoRegexStr);
                if(content.Contains("快递"))
                {
                    content = content.Insert(content.IndexOf("快递") + 2, " ");
                }
                //string[] arr = content.Split('\n');
                ArrayList arr = getContinueParcelNumber(content);
                foreach (string strLine in arr)
                {

                    string[] tmpArr = strLine.Split(' ');
                    foreach (string val in tmpArr)
                    {
                        string valN = val;
                        string curV = val;
                        if (isContainChinese(val, out valN))
                        {
                            curV = valN;
                        }
                        
                        if (curV.Length > 5 )
                        {
                            if(curV.Length>=14)
                            {
                                string newV = curV.Substring(0, 14);
                                if(ztoRegex.IsMatch(newV))
                                {
                                    arListZto.Add(curV);
                                    if (!taskBean.arListWaybills.Contains(curV))
                                    {
                                        taskBean.arListWaybills.Add(curV);
                                    }
                                }
                            }
                            
                           

                        }
                    }
                }
                if (arListZto.Count > 0)
                {
                    res = true;
                }

            }
            catch (Exception ex)
            {

            }
            return res;
        }

        public ArrayList getContinueParcelNumber(string text)
        {
            ArrayList arList = new ArrayList();
            try
            {
                string newText = text;
                string[] arrTmp = text.Split(new string[] { "\r\n","\n"," ",",","，" }, StringSplitOptions.None);
                foreach(string tmpV in arrTmp)
                {
                    if(tmpV.Contains("-")&& tmpV.Length>20&&MathUtility.ImpIsNum(tmpV.Replace("-","")))
                    {
                        string[] arr = tmpV.Split('-');
                        if(arr[0].Length==6)
                        {
                            newText = newText.Replace(tmpV, "");
                            newText = newText.TrimStart('\n');
                        }
                    }
                }

                char[] c = newText.ToCharArray();
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < newText.Length; i++)
                {
                    char ch = c[i];
                    if (ch < '0' || ch > '9')
                    {
                       if(sb.ToString().Length>0&&(ch != 'J'&& ch != 'T')&& (ch != 'Y' && ch != 'T'))
                       {
                            arList.Add(sb.ToString());
                            sb.Clear();
                       }
                       else
                       {
                            if(ch=='J' || ch == 'Y' || ch=='T')
                            {
                                sb.Append(ch.ToString());
                            }
                       }
                        
                    }
                    else
                    {
                        sb.Append(ch.ToString());
                    }


                }
                if(sb.ToString().Length>10)
                {
                    arList.Add(sb.ToString());
                }
               
            }
            catch(Exception ex)
            {

            }
            return arList;
        }

        public void removeJTBarcode(WechatMsgBean wechatBean,ArrayList arListInputs)
        {
            try
            {
                foreach(ParcelBean parcelBean in arListInputs)
                {
                    wechatBean.content = wechatBean.content.Replace(parcelBean.wayBill, "");
                }
            }
            catch(Exception ex)
            {

            }
        }

        public ArrayList getInputBarcodesAndAddr(string content, TaskBean taskBean)
        {
            ArrayList arListParcelInfos = new ArrayList();
            try
            {
                if(!content.Contains("JT"))
                {
                    return arListParcelInfos;
                }
                content = removeHeaderText(content);


                string numberPattern = @"^[0-9]{13}$|^(55)[0-9]{13}$";
                //string[] arr = content.Trim().Split("JT".ToCharArray(),StringSplitOptions.RemoveEmptyEntries);
                string strSub = "";
                if (content.Trim().Contains("单号"))
                {
                    strSub = content.Trim().Substring(content.Trim().LastIndexOf("单号") + 2);
                    if(strSub.Trim().StartsWith("JT")&& strSub.Trim().Length==15)
                    {
                        content = content.Replace(strSub, "");
                    }
                }
                string[] arr = content.Trim().Split(new string[] { "JT" }, StringSplitOptions.RemoveEmptyEntries);
                arr[arr.Length - 1] = arr[arr.Length - 1] + strSub;
                string wechatName = "";
                string groupName = "";
                bool isTransfer = false;
                if(arr[0].Trim().EndsWith("中转"))
                {
                    isTransfer = true;
                    arr[0] = arr[0].Replace("中转", "").Trim();
                    /*if(arr[0].Length==15)
                    {
                        StoParams.Instance.taskCode = arr[0];
                    }
                    else
                    {
                        StoParams.Instance.taskCode = arr[0].Substring(0, 15);
                    }*/
                    


                }
                string barcode = "";
                string realOriAddr = "";
                if (arr.Length==2)
                {
                    
                    if(arr[1].Length>=13)
                    {
                        barcode =arr[1].Substring(0, 13);                        
                    }

                    ArrayList arListBarcodes = getJtBarcode(content);
                    if(arListBarcodes.Count==1)
                    {
                        if (isInterCept(arr[0]) && !isInterCept(arr[1]))
                        {
                            arr[1] = arr[1] + " 拦截退回";
                        }
                        else if (isChangeAddr(arr[0], barcode) && !isChangeAddr(arr[1], barcode))
                        {
                            arr[1] = arr[1] + " 改地址";
                        }

                        if (MathUtility.ImpIsNum(barcode))
                        {
                            if (arr[1].Length >= 13)
                            {
                                string subMsg = arr[1].Replace(barcode, "");
                                if (subMsg.Length >= 2)
                                {
                                    if (arr[0].Trim().Length >= 2 && (!MathUtility.ImpIsNum(arr[0])))
                                    {
                                        arr[1] = barcode + " " + subMsg + " " + arr[0];

                                        if (arr[1].Contains("发货物流公司") && arr[1].Contains("发货快递单号"))
                                        {
                                            int startIndex = arr[1].IndexOf("发货物流公司");
                                            int endIndex = arr[1].IndexOf("发货快递单号");
                                            if (endIndex > startIndex)
                                            {
                                                arr[1] = arr[1].Remove(startIndex, endIndex + 6 - startIndex);
                                            }

                                        }
                                    }
                                    else
                                    {

                                    }
                                }

                                //realOriAddr = arr[0];
                            }
                        }
                        else
                        {
                            arr[0] = arr[0] + "JT" + arr[1];
                        }
                    }
                    

                    
                }
                for (int i = 0; i < arr.Length; i++)
                {
                    string sbuCode ="";
                    if(arr[i].Length>=13)
                    {
                        sbuCode = arr[i].Substring(0, 13);
                    }
                    
                    Regex numberPatter = new Regex(numberPattern);
                    if (!numberPatter.Match(sbuCode).Success)
                    {
                        continue;
                    }
                    else
                    {
                        if(arr[i].Contains(sbuCode))
                        {
                            string nestNumCode = arr[i].Replace(sbuCode, "");
                            /*if(nestNumCode.Length>=5)
                            {
                                nestNumCode = nestNumCode.Substring(0, 5);
                                try
                                {
                                    int iNumCode = Convert.ToInt32(nestNumCode);
                                    continue;
                                }
                                catch(Exception ex)
                                {

                                }
                            }*/
                        }
                        
                    }

                    if (arr[i].Length == 14 && (arr[i].EndsWith(",") || arr[i].EndsWith( "，") || arr[i].EndsWith(" ")))
                    {
                        arr[i] = arr[i].Substring(0,13);
                    }
                    else
                    {
                        arr[i] = arr[i].Substring(0, 13);
                    }
                }
                for (int i=0;i< arr.Length;i++)
                {
                    if(arr[i].Contains("%&"))
                    {
                        wechatName = arr[i].Substring(0, arr[i].IndexOf("%&"));
                        if(barcode.Contains(wechatName))
                        {
                            wechatName = "";
                        }
                        if(wechatName.Contains("*"))
                        {                            
                            groupName = wechatName.Substring(wechatName.IndexOf('*') + 1);
                            wechatName = wechatName.Substring(0, wechatName.IndexOf('*'));
                        }
                    }
                    if(arr[i].Length<13)
                    {
                        continue;
                    }

                    string sbuCode = arr[i].Substring(0, 13);
                    Regex numberPatter = new Regex(numberPattern);
                    if(!numberPatter.Match(sbuCode).Success)
                    {
                        continue;
                    }
                    else
                    {
                        if (arr[i].Contains(sbuCode))
                        {
                            string nestNumCode = arr[i].Replace(sbuCode, "");
                            if (nestNumCode.Length >= 5)
                            {
                                nestNumCode = nestNumCode.Substring(0, 5);
                                try
                                {
                                    int iNumCode = Convert.ToInt32(nestNumCode);
                                    continue;
                                }
                                catch (Exception ex)
                                {

                                }
                            }
                        }
                    }
                    string parcelCode = "JT" + sbuCode;
                    ParcelBean parcelBean = new ParcelBean();
                    parcelBean.wayBill = parcelCode;
                    parcelBean.addr = arr[i].Substring(13);
                    parcelBean.ori_addr = arr[i].Substring(13);
                    if(isTransfer)
                    {
                        parcelBean.ori_addr = "中转";
                        parcelBean.addr = "中转";
                    }
                    if(MathUtility.ImpIsNum(parcelBean.ori_addr))
                    {
                        parcelBean.ori_addr = "";
                        parcelBean.addr = "";
                    }
                    if(parcelBean.ori_addr.Length==1&&(parcelBean.ori_addr==","|| parcelBean.ori_addr == "，" || parcelBean.ori_addr == " "))
                    {
                        parcelBean.ori_addr = "";
                        parcelBean.addr = "";
                    }
                    if(parcelBean.ori_addr.Trim()=="")
                    {
                        parcelBean.ori_addr = getFirstTaskType(i, arr);
                        parcelBean.addr = parcelBean.ori_addr;
                    }
                    if(parcelBean.ori_addr.Length>0&& parcelBean.ori_addr.Length<10&& parcelBean.ori_addr.Contains("改地址"))
                    {
                        if(arr[0].Length>20)
                        {
                            parcelBean.ori_addr = parcelBean.ori_addr + arr[0];
                            parcelBean.addr = parcelBean.ori_addr;
                        }
                    }

                    else if (parcelBean.ori_addr.Trim() == "")
                    {
                        if (arr.Length == 2)
                        {
                            if (!arr[0].Contains(sbuCode))
                            {
                                parcelBean.ori_addr = arr[0];
                                parcelBean.addr = arr[0];
                            }
                            else if (!arr[1].Contains(sbuCode))
                            {
                                parcelBean.ori_addr = arr[1];
                                parcelBean.addr = arr[1];
                            }
                        }
                    }
                    else if(parcelBean.ori_addr.Trim() == "")
                    {
                        
                        string substr = "";
                        if(content.Contains("%&"))
                        {
                            substr = content.Substring(content.IndexOf("%&") + 2);
                        }
                        if (substr.Contains(parcelCode))
                        {
                            substr = substr.Replace(parcelCode, "");
                            parcelBean.ori_addr = substr;
                            parcelBean.addr = substr;
                        }                      

                    }
                    else if(getCleanMsg(parcelBean.ori_addr.Trim()).Length<2)
                    {
                        parcelBean.ori_addr = "";
                        parcelBean.addr = "";
                    }
                    
                    parcelBean.wechat = wechatName;
                    parcelBean.senderWeChat = groupName;
                    getInputAddr(parcelBean);
                    arListParcelInfos.Add(parcelBean);
                }

                bool isAllEmpty = true;
                foreach(ParcelBean parcel in arListParcelInfos)
                {
                    if(!taskBean.arListWaybills.Contains(parcel.wayBill))
                    {
                        taskBean.arListWaybills.Add(parcel.wayBill);
                    }                
                    
                    if (parcel.ori_addr.Length>1)
                    {
                        isAllEmpty = false;
                    }
                }
                if(isAllEmpty)
                {
                    string oriAddr = "";
                    if(content.Contains("JT"))
                    {
                        oriAddr = content.Substring(0, content.IndexOf("JT"));
                        if(oriAddr.Trim().Length>1)
                        {
                            foreach (ParcelBean parcel in arListParcelInfos)
                            {
                                if(parcel.ori_addr.Length<2)
                                {
                                    parcel.ori_addr = oriAddr;
                                }
                                
                            }
                        }
                            
                    }
                }
           

            }
            catch(Exception ex)
            {

            }
            return arListParcelInfos;
        }



        public ArrayList getYTInputBarcodesAndAddr(string content,TaskBean taskBean)
        {
            ArrayList arListParcelInfos = new ArrayList();
            try
            {
                if (!content.Contains("YT"))
                {
                    return arListParcelInfos;
                }
                content = removeHeaderText(content);


                string numberPattern = @"^[0-9]{13}$";
                //string[] arr = content.Trim().Split("JT".ToCharArray(),StringSplitOptions.RemoveEmptyEntries);
                string strSub = "";
                if (content.Trim().Contains("单号"))
                {
                    strSub = content.Trim().Substring(content.Trim().LastIndexOf("单号") + 2);
                    if (strSub.Trim().StartsWith("YT") && strSub.Trim().Length == 13)
                    {
                        content = content.Replace(strSub, "");
                    }
                }
                string[] arr = content.Trim().Split(new string[] { "YT" }, StringSplitOptions.RemoveEmptyEntries);
                arr[arr.Length - 1] = arr[arr.Length - 1] + strSub;
                string wechatName = "";
                string groupName = "";
                bool isTransfer = false;
                if (arr[0].Trim().EndsWith("中转"))
                {
                    isTransfer = true;
                    arr[0] = arr[0].Replace("中转", "").Trim();
                    /*if(arr[0].Length==15)
                    {
                        StoParams.Instance.taskCode = arr[0];
                    }
                    else
                    {
                        StoParams.Instance.taskCode = arr[0].Substring(0, 15);
                    }*/

                }
                string barcode = "";
                string realOriAddr = "";
                if (arr.Length == 2)
                {

                    if (arr[1].Length >= 13)
                    {
                        barcode = arr[1].Substring(0, 13);
                    }

                    ArrayList arListBarcodes = getYTBarcode(content);
                    if (arListBarcodes.Count == 1)
                    {
                        if (isInterCept(arr[0]) && !isInterCept(arr[1]))
                        {
                            arr[1] = arr[1] + " 拦截退回";
                        }
                        else if (isChangeAddr(arr[0], barcode) && !isChangeAddr(arr[1], barcode))
                        {
                            arr[1] = arr[1] + " 改地址";
                        }

                        if (MathUtility.ImpIsNum(barcode))
                        {
                            if (arr[1].Length >= 13)
                            {
                                string subMsg = arr[1].Replace(barcode, "");
                                if (subMsg.Length >= 2)
                                {
                                    if (arr[0].Trim().Length >= 2 && (!MathUtility.ImpIsNum(arr[0])))
                                    {
                                        arr[1] = barcode + " " + subMsg + " " + arr[0];

                                        if (arr[1].Contains("发货物流公司") && arr[1].Contains("发货快递单号"))
                                        {
                                            int startIndex = arr[1].IndexOf("发货物流公司");
                                            int endIndex = arr[1].IndexOf("发货快递单号");
                                            if (endIndex > startIndex)
                                            {
                                                arr[1] = arr[1].Remove(startIndex, endIndex + 6 - startIndex);
                                            }

                                        }
                                    }
                                    else
                                    {

                                    }
                                }

                                //realOriAddr = arr[0];
                            }
                        }
                        else
                        {
                            arr[0] = arr[0] + "YT" + arr[1];
                        }
                    }



                }

                string leftChinese = "";
                for (int i = 0; i < arr.Length; i++)
                {
                    string sbuCode = "";
                    if (arr[i].Length >= 13)
                    {
                        sbuCode = arr[i].Substring(0, 13);
                    }

                    Regex numberPatter = new Regex(numberPattern);
                    if (!numberPatter.Match(sbuCode).Success)
                    {
                        continue;
                    }
                    else
                    {
                        if (arr[i].Contains(sbuCode))
                        {
                            string nestNumCode = arr[i].Replace(sbuCode, "");
                            nestNumCode = nestNumCode.Replace("\n", "");
                            leftChinese = nestNumCode;

                            /*if(nestNumCode.Length>=5)
                            {
                                nestNumCode = nestNumCode.Substring(0, 5);
                                try
                                {
                                    int iNumCode = Convert.ToInt32(nestNumCode);
                                    continue;
                                }
                                catch(Exception ex)
                                {

                                }
                            }*/
                        }

                    }

                    if (arr[i].Length == 14 && (arr[i].EndsWith(",") || arr[i].EndsWith("，") || arr[i].EndsWith(" ")))
                    {
                        arr[i] = arr[i].Substring(0, 13);
                    }
                    else
                    {
                        arr[i] = arr[i].Substring(0, 13);
                    }
                }
                for (int i = 0; i < arr.Length; i++)
                {
                    if (arr[i].Contains("%&"))
                    {
                        wechatName = arr[i].Substring(0, arr[i].IndexOf("%&"));
                        if (barcode.Contains(wechatName))
                        {
                            wechatName = "";
                        }
                        if (wechatName.Contains("*"))
                        {
                            groupName = wechatName.Substring(wechatName.IndexOf('*') + 1);
                            wechatName = wechatName.Substring(0, wechatName.IndexOf('*'));
                        }
                    }
                    if (arr[i].Length < 13)
                    {
                        continue;
                    }

                    string sbuCode = arr[i].Substring(0, 13);
                    Regex numberPatter = new Regex(numberPattern);
                    if (!numberPatter.Match(sbuCode).Success)
                    {
                        continue;
                    }
                    else
                    {
                        if (arr[i].Contains(sbuCode))
                        {
                            string nestNumCode = arr[i].Replace(sbuCode, "");
                            if (nestNumCode.Length >= 5)
                            {
                                nestNumCode = nestNumCode.Substring(0, 5);
                                try
                                {
                                    int iNumCode = Convert.ToInt32(nestNumCode);
                                    continue;
                                }
                                catch (Exception ex)
                                {

                                }
                            }
                        }
                    }
                    string parcelCode = "YT" + sbuCode;
                    ParcelBean parcelBean = new ParcelBean();
                    parcelBean.wayBill = parcelCode;
                    parcelBean.addr = arr[i].Substring(13);
                    parcelBean.ori_addr = arr[i].Substring(13);
                    if(parcelBean.addr==""&&leftChinese.Length>1)
                    {
                        parcelBean.addr = leftChinese;
                        parcelBean.ori_addr= leftChinese;
                    }
                    if (isTransfer)
                    {
                        parcelBean.ori_addr = "中转";
                        parcelBean.addr = "中转";
                    }
                    if (MathUtility.ImpIsNum(parcelBean.ori_addr))
                    {
                        parcelBean.ori_addr = "";
                        parcelBean.addr = "";
                    }
                    if (parcelBean.ori_addr.Length == 1 && (parcelBean.ori_addr == "," || parcelBean.ori_addr == "，" || parcelBean.ori_addr == " "))
                    {
                        parcelBean.ori_addr = "";
                        parcelBean.addr = "";
                    }
                    if (parcelBean.ori_addr.Trim() == "")
                    {
                        parcelBean.ori_addr = getFirstTaskType(i, arr);
                        parcelBean.addr = parcelBean.ori_addr;
                    }
                    if (parcelBean.ori_addr.Length > 0 && parcelBean.ori_addr.Length < 10 && parcelBean.ori_addr.Contains("改地址"))
                    {
                        if (arr[0].Length > 20)
                        {
                            parcelBean.ori_addr = parcelBean.ori_addr + arr[0];
                            parcelBean.addr = parcelBean.ori_addr;
                        }
                    }

                    else if (parcelBean.ori_addr.Trim() == "")
                    {
                        if (arr.Length == 2)
                        {
                            if (!arr[0].Contains(sbuCode))
                            {
                                parcelBean.ori_addr = arr[0];
                                parcelBean.addr = arr[0];
                            }
                            else if (!arr[1].Contains(sbuCode))
                            {
                                parcelBean.ori_addr = arr[1];
                                parcelBean.addr = arr[1];
                            }
                        }
                    }
                    else if (parcelBean.ori_addr.Trim() == "")
                    {

                        string substr = "";
                        if (content.Contains("%&"))
                        {
                            substr = content.Substring(content.IndexOf("%&") + 2);
                        }
                        if (substr.Contains(parcelCode))
                        {
                            substr = substr.Replace(parcelCode, "");
                            parcelBean.ori_addr = substr;
                            parcelBean.addr = substr;
                        }

                    }
                    else if (getCleanMsg(parcelBean.ori_addr.Trim()).Length < 2)
                    {
                        parcelBean.ori_addr = "";
                        parcelBean.addr = "";
                    }

                    parcelBean.wechat = wechatName;
                    parcelBean.senderWeChat = groupName;
                    getInputAddr(parcelBean);
                    arListParcelInfos.Add(parcelBean);
                }

                bool isAllEmpty = true;
                foreach (ParcelBean parcel in arListParcelInfos)
                {
                    if (!taskBean.arListWaybills.Contains(parcel.wayBill))
                    {
                        taskBean.arListWaybills.Add(parcel.wayBill);
                    }

                    if (parcel.ori_addr.Length > 1)
                    {
                        isAllEmpty = false;
                    }
                }
                if (isAllEmpty)
                {
                    string oriAddr = "";
                    if (content.Contains("YT"))
                    {
                        oriAddr = content.Substring(0, content.IndexOf("YT"));
                        if (oriAddr.Trim().Length > 1)
                        {
                            foreach (ParcelBean parcel in arListParcelInfos)
                            {
                                if (parcel.ori_addr.Length < 2)
                                {
                                    parcel.ori_addr = oriAddr;
                                }

                            }
                        }

                    }
                }


            }
            catch (Exception ex)
            {

            }
            return arListParcelInfos;
        }


        public string getCleanMsg(string msg)
        {
            string res = msg;
            try
            {
                if(msg.Trim().Replace("\n","").Length<10)
                {
                    if(res.EndsWith("：")|| res.EndsWith(":"))
                    {
                        res = res.Substring(0, res.Length - 1);
                    }
                    res = res.Replace("\n", "");
                    res = res.Replace("运单号码", "");
                    res = res.Replace("快递单号", "");
                    res = res.Replace("运单号", "");
                    res = res.Replace("单号", "");
                    res = res.Replace("物流单号", "");
                    res = res.Replace("极兔速递", "");
                    res = res.Replace("发货单号", "");
                }
            }
            catch(Exception ex)
            {

            }
            return res;
        }

        private string getFirstTaskType(int curIndex,string[] arr)
        {
            string res = "";
            try
            {
                string numberPattern = @"^[0-9]{13}$|^(55)[0-9]{13}$";
                for (int i= curIndex;i< arr.Length;i++)
                {
                    if (arr[i].Length < 13)
                    {
                        continue;
                    }
                    string sbuCode = arr[i].Substring(0, 13);
                    Regex numberPatter = new Regex(numberPattern);
                    if (!numberPatter.Match(sbuCode).Success)
                    {
                        continue;
                    }
                    string parcelCode = "JT" + sbuCode;

                    string addr = arr[i].Substring(13);
                    if(addr.Trim()!=""&& addr.Trim().Length>=1&&!MathUtility.ImpIsNum(addr.Replace("\n","")))
                    {
                        res = addr.Trim();
                        break;
                    }
                    
                }
            }
            catch(Exception ex)
            {

            }
            if (res == "催")
            {
                res = "催件";
            }
            if (res == "拦")
            {
                res = "拦截";
            }
            if (res == "退")
            {
                res = "拦截";
            }
            return res;
        }




        public ArrayList getInputParcels(string content)
        {
            ArrayList arListParcelInfos = new ArrayList();
            try
            {
                if (!content.Contains("JT"))
                {
                    return arListParcelInfos;
                }
                string numberPattern = @"^[0-9]{13}$|^(55)[0-9]{13}$";
                //string[] arr = content.Trim().Split("JT".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                string[] arr = content.Trim().Split(new string[] { "JT" }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < arr.Length; i++)
                {
                    string sbuCode = arr[i].Substring(0, 13);
                    Regex numberPatter = new Regex(numberPattern);
                    if (!numberPatter.Match(sbuCode).Success)
                    {
                        continue;
                    }
                    string parcelCode = "JT" + sbuCode;
                    ParcelBean parcel = new ParcelBean();
                    parcel.wayBill = parcelCode;
                    arListParcelInfos.Add(parcel);
                }


            }
            catch (Exception ex)
            {

            }
            return arListParcelInfos;
        }


        public void parseIsYishi(ParcelBean parcleBean)
        {
            if (parcleBean.ori_addr.Contains("破损"))
            {
                parcleBean.isYishi = false;
                return;
            }
            if (parcleBean.ori_addr.Contains("未收到") || parcleBean.ori_addr.Contains("没有收到") || parcleBean.ori_addr.Contains("没收到"))
            {
                parcleBean.isYishi = true;
            }
            
  
        }



        public bool parseInterceptIsOutWarehouse(ParcelBean parcleBean, ArrayList arListRoadMap)
        {
            bool res = false;
            try
            {
                RoadBean roadBean = getLastValidScanRoadBean(arListRoadMap, StoParams.Instance.register_site);
                if(roadBean.scanTypeName.Contains("出仓扫描")|| roadBean.scanTypeName.Contains("入库扫描"))
                {
                    res = true;
                    parcleBean.isOutWareHouse = true;
                }

            }
            catch (Exception ex)
            {

            }
            return res;
        }



        public void parseIsYishi(ParcelBean parcleBean,ArrayList arListRoadMap)
        {
            if(parcleBean.ori_addr.Contains("破损")|| parcleBean.ori_addr.Contains("短少") 
                || parcleBean.ori_addr.Contains("污染") || parcleBean.ori_addr.Contains("少件")
                || parcleBean.ori_addr.Contains("空包"))
            {
                parcleBean.isYishi = false;
                return;
            }
            if (parcleBean.ori_addr.Contains("未收到") || 
                parcleBean.ori_addr.Contains("没有收到") ||
                parcleBean.ori_addr.Contains("没收到") ||
                 parcleBean.ori_addr.Contains("丢件") ||
                parcleBean.ori_addr.Contains("遗失"))
            {
                parcleBean.isYishi = true;
            }
            try
            {
                RoadBean roadBean = getLastValidScanRoadBean(arListRoadMap, StoParams.Instance.register_site);
                if(roadBean.status=="已签收"|| roadBean.scanTypeName == "已签收" || roadBean.scanTypeName == "完结")
                {
                    parcleBean.isYishi = true;
                    return;
                }

                if(isFinishedOverTime(arListRoadMap, StoParams.Instance.register_site))
                {
                    parcleBean.isYishi = true;
                    return;
                }
                string scanTime = roadBean.scanTime;
                DateTime dtScan = Convert.ToDateTime(scanTime);
                TimeSpan ts = System.DateTime.Now - dtScan;
                if(ts.TotalHours>96)
                {
                    parcleBean.isYishi = true;
                }

            }
            catch(Exception ex)
            {

            }
        }

        public string getChangedAddr(string oriAddr,string barcode)
        {
            string res = oriAddr;
            try
            {
                string changeChar = "";

                if(oriAddr.Contains("改地址")&& oriAddr.Contains("原地址"))
                {
                    if(oriAddr.IndexOf("原地址")- oriAddr.IndexOf("改地址")>15)
                    {
                        res = oriAddr.Substring(0, oriAddr.IndexOf("原地址"));
                    }
                }
                if(res.Contains("改地址"))
                {
                    changeChar = "改地址";
                }
                else if (res.Contains("换地址"))
                {
                    changeChar = "换地址";
                }
                else if (res.Contains("修改收货地址"))
                {
                    changeChar = "修改收货地址";
                }
                else if (res.Contains("修改收件地址"))
                {
                    changeChar = "修改收件地址";
                }
                else if (res.Contains("地址"))
                {
                    changeChar = "地址";
                }
                string[] arr = res.Split('\n');
                string oriContent = res;
                string phoneNum = "";
                List<string> tr = GetTelephoneList(res, barcode);
                if(tr.Count>0)
                {
                    phoneNum = tr[tr.Count-1].ToString();
                }
                res = res.Substring(res.IndexOf(changeChar) + changeChar.Length);
                if(res.Contains("新地址"))
                {
                    res = res.Substring(res.IndexOf("新地址") + 3);
                }

                res = res.Trim().TrimStart('：');
                res = res.Trim().TrimStart(':').Trim();
                //res = res.Replace("，", " ");
                //res = res.Replace("。", " ");

                if (res.Length<3)
                {
                    if(oriAddr.Contains(changeChar))
                    {
                        res = oriAddr.Substring(0, oriAddr.IndexOf(changeChar));
                    }
                    
                }
                else if(!res.Contains(phoneNum))
                {
                    string strSub = oriContent.Substring(0, oriContent.IndexOf(phoneNum) + phoneNum.Length);
                    if(strSub.Contains("区")&& strSub.Contains("市")&& res.Contains("市")&& res.Length>10)
                    {
                        res = res + " 电话" + phoneNum;

                    }
                    else
                    {
                        res = strSub + "\n" + res;
                    }
                    
                }
                else if(res.Contains(phoneNum)&& res.Trim().EndsWith(phoneNum))
                {

                }
                res = res.Trim(',');


            }
            catch(Exception ex)
            {

            }
            return res;
        }


        public string getNameFirstAddr(string oriAddr)
        {
            string res = oriAddr;
            try
            {
                string changeChar = "";              
                string[] arr = res.Split('\n');
                string oriContent = res;
                string phoneNum = "";
                List<string> tr = GetTelephoneList(res, "123");
                if (tr.Count > 0)
                {
                    phoneNum = tr[tr.Count - 1].ToString();
                }
                res = res.Substring(res.IndexOf(changeChar) + changeChar.Length);
                res = res.Trim().TrimStart('：');
                res = res.Replace("，", " ");
                res = res.Replace("。", " ");

                if (res.Length < 3)
                {
                    if (oriAddr.Contains(changeChar))
                    {
                        res = oriAddr.Substring(0, oriAddr.IndexOf(changeChar));
                    }

                }
           
                if (res.Contains(phoneNum) && res.Trim().EndsWith(phoneNum))
                {
                    for(int start= res.LastIndexOf(phoneNum)-2;start> res.LastIndexOf(phoneNum)-6; start--)
                    {
                        if(IsSpecialChar(res.Substring(start,1)))
                        {
                            string sub = res.Substring(start);
                            res = sub + " " + res.Replace(sub, "");
                            break;
                        }
                    }
                }
                res = res.Trim(',');


            }
            catch (Exception ex)
            {

            }
            return res;
        }

        public bool IsSpecialChar(string str)
        {
            Regex regExp = new Regex("[ \\[ \\] \\^ \\-_*×――(^)$%~!＠@＃#$…&%￥—+=<>《》!！??？:：•`·、。，；,.;/\'\"{}（）‘’“”-]");
            if (regExp.IsMatch(str))
            {
                return true;
            }
            return false;
        }

        public string getInputAddr(ParcelBean parcelBean)
        {
            string res = "";
            try
            {                
                string addr = parcelBean.addr;
                if(addr.Length>50)
                {
                    List<string> list = new List<string>();
                    Regex regex = new Regex(@"(\D1[3|4|5|6|7|8|9]\d{9}\D)");
                    MatchCollection collection = regex.Matches(parcelBean.addr);
                    foreach (Match item in collection)
                    {
                        foreach (Group group in item.Groups)
                        {
                            string telephone = group.Value.Trim();
                            if (!string.IsNullOrEmpty(telephone))
                            {
                                addr = addr.Substring(0, addr.IndexOf(telephone) + telephone.Length);
                                parcelBean.addr = addr;
                                return res;

                            }
                        }
                    }
                }
       


            }
            catch (Exception ex)
            {

            }
            return res;
        }


        public string getPhoneNum(string content,string barcode)
        {
            string res = "";
            try
            {
                content = content.Replace(barcode,"");

            }
            catch(Exception ex)
            {
                
            }
            return res;
        }

        /// <summary>
        /// 提取字符串中的电话号
        /// * 兼容11位手机号、3位或4位区号+8位电话号、400电话的两种写法(400-ddd-dddd、400ddddddd)
        /// </summary>
        /// <param name="input">输入的字符串</param>
        /// <returns></returns>
        public  List<string> GetTelephoneList(string input, string barcode)
        {
            input = input.Replace(barcode, "");
            //集合存放提取出来的电话号码
            List<string> list = new List<string>();
            try
            {
                /*
             * 正则表达式提取
             * 分为五种格式，能兼容11位手机号、3位或4位区号-7位或8位电话号、400电话的两种写法(400-ddd-dddd、400ddddddd)
             */
                Regex regex = new Regex(@"(1[3|4|5|6|7|8|9]\d{9})|(0\d{2,3}-\d{7,8})|(400-\d{3}-\d{4})|(400\d{7})");

                //Match集合，匹配成功的字符串集合
                MatchCollection collection = regex.Matches(input);

                //遍历Match集合，取出值
                string telephone;
                foreach (Match item in collection)
                {
                    foreach (Group group in item.Groups)
                    {
                        telephone = group.Value.Trim();
                        //偶尔会出现重复提取，所以加了去重判断
                        if (!string.IsNullOrEmpty(telephone) && !list.Contains(telephone) && !isContainTel(list, telephone))
                        {
                            int nextCharIndex = input.IndexOf(telephone) + telephone.Length;
                            if (nextCharIndex < input.Length - 1)
                            {
                                string nextchar = input.Substring(nextCharIndex, 1);
                                if (nextchar == "-" || nextchar == "—")
                                {
                                    string parNum = getPartNum(input.Substring(nextCharIndex + 1));
                                    if (parNum.Length <= 4 && parNum.Length >= 3)
                                    {
                                        telephone = telephone + "-" + parNum;
                                    }
                                }
                            }
                            list.Add(telephone);
                        }
                    }
                }
            }
            catch (Exception ex)
            {

            }



            return list;
        }

        public bool isContainTel(List<string> list,string telPhone)
        {
            bool res = false;
            try
            {
                foreach(string strPhone in list)
                {
                    if(strPhone.Contains(telPhone))
                    {
                        res = true;
                        break;
                    }
                }

            }
            catch(Exception ex)
            {

            }
            return res;

        }

        public string getPartNum(string parNum)
        {
            string res = "";
            try
            {
                foreach (char item in parNum)
                {
                    if (item >= 48 && item <= 58)
                    {
                        res += item;
                    }
                    else
                    {
                        break;
                    }
                }

            }
            catch(Exception ex)
            {

            }
            return res;

        }

        public  string getUsefullContent(string leaveMsg, string siteName)
        {
            string subStr = "";
            string priHeader = "";
            if (leaveMsg.Contains("协商加微信"))
            {
                subStr = leaveMsg.Substring(leaveMsg.IndexOf("协商加微信"));
            }
            else if (leaveMsg.Contains("遗失理赔+"))
            {
                subStr = leaveMsg.Substring(leaveMsg.IndexOf("遗失理赔+"));
            }
            if(subStr.Length>1)
            {
                priHeader = leaveMsg.Replace(subStr, "");
            }
            string res = leaveMsg;

            List<string> phoneList = GetTelephoneList(leaveMsg, "123");
            try
            {
                if (res.Length < 100)
                {
                    return res;
                }
                if (leaveMsg.Contains(siteName))
                {
                    res = res.Replace(siteName, "贵司");
                }
                res = res.Replace("到件贵司", "在贵司到件");
                if (res.Replace(" ", "").Length < 100)
                {
                    return res.Replace(" ", "");
                }
                int indexStr = 0;
                if(res.Contains("省"))
                {
                    indexStr = res.IndexOf("省");
                }
                else if(res.Contains("市"))
                {
                    indexStr = res.IndexOf("市");
                }
                if(indexStr>0)
                {
                    char[] chars = res.ToCharArray();
                    for(int curIndex= indexStr; curIndex>0; curIndex--)
                    {
                        string curStr = res.Substring(curIndex, 1);
                        int n = 0;
                        bool isNumeric = int.TryParse(curStr, out n);
                        if(isNumeric)
                        {
                            res = res.Substring(0, curIndex+1);
                            break;
                        }
                    }

                }
                if(phoneList.Count>0)
                {
                    string phone = phoneList[0];
                    if(!res.Contains(phone))
                    {
                        if(priHeader.Contains("地址"))
                        {
                            priHeader = priHeader.Substring(0, priHeader.IndexOf("地址"));
                            if(!priHeader.Contains(phone))
                            {
                                priHeader = priHeader + "电话:" + phone;
                            }
                            res = priHeader;

                        }
                        else
                        {
                            if(priHeader.Contains(phone))
                            {
                                bool containSubNum = false;
                                int phoneIndex = priHeader.IndexOf(phone) + phone.Length;
                                string subNum = "";
                                string nextChar = priHeader.Substring(phoneIndex, 1);
                                if(nextChar=="-")
                                {
                                    containSubNum = true;
                                }
                                if((priHeader.Substring(phoneIndex).Contains("转")|| priHeader.Substring(phoneIndex).Contains("分机号"))||
                                    (priHeader.Contains("[")&& priHeader.Contains("]")))
                                {
                                    containSubNum = true;
                                }
                                if(containSubNum)
                                {
                                    phone = priHeader.Substring(priHeader.IndexOf(phone));
                                    if(phone.Contains("协商"))
                                    {
                                        phone = phone.Substring(0, phone.IndexOf("协商"));
                                    }
                                }
                                if(indexStr>0)
                                {
                                    if(priHeader.Contains("。"))
                                    {
                                        priHeader = priHeader.Substring(0, priHeader.IndexOf('。')+1);
                                    }
                                    else
                                    {
                                        priHeader = priHeader.Substring(0, indexStr - 3);
                                    }
                                    
                                }
                                if (!res.Contains(phone))
                                {
                                    priHeader = priHeader + " 电话:" + phone;
                                }
                                res = priHeader;


                            }

                        }
                       

                    }

                }
           
                if(res.Length<80)
                {
                    res = res +" "+ subStr;
                }
                if(res.Length>100)
                {
                    res = res.Substring(0, 100);
                }
                if(leaveMsg.Length<38&& leaveMsg.Contains("号"))
                {
                    if(leaveMsg.Length>100)
                    {
                        res = leaveMsg.Substring(0, 100);
                    }
                    
                }             
                
            }
            catch (Exception ex)
            {

            }
            return res;

        }

        public void getAddrChangedOnly(ParcelBean parcelBean,string bingoKeyWord)
        {
            try
            {
                if(parcelBean.ori_addr.Contains(bingoKeyWord))
                {
                    parcelBean.ori_addr = parcelBean.ori_addr.Substring(parcelBean.ori_addr.IndexOf(bingoKeyWord) + bingoKeyWord.Length);
                    parcelBean.ori_addr = parcelBean.ori_addr.Trim().TrimStart('：');
                }
            }
            catch(Exception ex)
            {

            }
        }

        public bool checkToken(string token)
        {
            bool res = false;
            try
            {
                string strUrl = "https://jmsgw.jtexpress.com.cn/basicdata/checkToken";
            }
            catch(Exception ex)
            {

            }
            return res;
        }



        public bool resetToken(string wayBills, out string pickNetName, out string orderSource, out string curPickSiteToken, out string customerName, out string realPickName)
        {
            bool findMapNet = false;
            pickNetName = "";
            orderSource = "";
            curPickSiteToken = "";
            customerName = "";
            realPickName = "";
            bool checkLanshouSite = false;
            try
            {
                JObject jObjDetail = new JObject();
                jObjDetail["waybillNo"] = wayBills;
                jObjDetail["countryId"] = "1";

                string strUrl = "https://jmsgw.jtexpress.com.cn/operatingplatform/order/getOrderDetail";
                if (StoParams.Instance.isRabbitWin)
                {
                    strUrl = "https://wdgw.jtexpress.com.cn/ops/wdbutler/order/getOrderDetail";
                }

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObjDetail);
                string res = HttpClient.HttpUtil.Instance.PostCommon(strUrl, postData, "trackingExpress");
                totalQueryCount++;
                if (res.Contains("data"))
                {
                    JObject jsonObj = (JObject)JsonConvert.DeserializeObject(res);
                    JObject dataArr = (JObject)jsonObj["data"];
                    if (dataArr != null)
                    {
                        JObject detailsRecords = (JObject)dataArr["details"];
                        string pickNetworkName = detailsRecords["pickNetworkName"].ToString();

                        string realPickNetworkName = detailsRecords["realPickNetworkName"].ToString();

                        if (pickNetworkName != realPickNetworkName && realPickNetworkName != "")
                        {
                            realPickName = realPickNetworkName;
                            pickNetName = pickNetworkName;

                            return false;
                        }

                        if (detailsRecords["orderSourceName"] != null)
                        {
                            orderSource = detailsRecords["orderSourceName"].ToString();
                        }

                        if (detailsRecords["customerName"] != null)
                        {
                            customerName = detailsRecords["customerName"].ToString();
                        }


                        if (pickNetworkName == "")
                        {
                            ArrayList arListAllGXTask3 = new ArrayList();
                            string httpRes3 = "";
                            ArrayList arListRoadMap3 = JTDelayHelper.Instance.getRoadMap(wayBills, out httpRes3, arListAllGXTask3);
                            pickNetworkName = JTDelayHelper.Instance.getLanShouSite(arListRoadMap3);
                        }
                        if (pickNetworkName != "")
                        {
                            pickNetName = pickNetworkName;
                        }

                        if (realPickNetworkName == "")
                        {
                            ArrayList arListAllGXTask3 = new ArrayList();
                            string httpRes3 = "";
                            ArrayList arListRoadMap3 = JTDelayHelper.Instance.getRoadMap(wayBills, out httpRes3, arListAllGXTask3);
                            realPickNetworkName = JTDelayHelper.Instance.getLanShouSite(arListRoadMap3);
                        }
                        if (realPickNetworkName != "")
                        {
                            pickNetName = realPickNetworkName;
                        }



                        if (StoParams.Instance.htRegInfo.ContainsKey(pickNetName) || StoParams.Instance.htRegInfo.ContainsKey(pickNetName.Replace("市", "")))
                        {
                            ArrayList arListRegBeans = StoParams.Instance.htRegInfo[pickNetName] as ArrayList;
                            foreach (RegBean regBean in arListRegBeans)
                            {
                                if (regBean.isLimitInterFace)
                                {
                                    DateTime dtNow = System.DateTime.Now;
                                    TimeSpan ts = dtNow - regBean.dtLimitTime;
                                    if (ts.TotalMinutes < 60)
                                    {
                                        continue;
                                    }

                                }

                                else if (!regBean.isAnthorized)
                                {
                                    DateTime dtNow = System.DateTime.Now;
                                    TimeSpan ts = dtNow - regBean.dtAnthorized;
                                    if (ts.TotalMinutes < 10)
                                    {
                                        continue;
                                    }

                                }
                                res = HttpClient.HttpUtil.Instance.PostCommonByToken(strUrl, postData, "trackingExpress", regBean.token);
                                if (res.Contains("data") && res.Contains("成功"))
                                {
                                    curPickSiteToken = regBean.token;
                                    MemberInfo.Instance.token = regBean.token;
                                    MemberInfo.Instance.templeteAssign = regBean.regWechate;
                                    MemberInfo.Instance.templeteCuijian = regBean.regWechate;
                                    MemberInfo.Instance.templeteQS = regBean.regWechate;
                                    MemberInfo.Instance.templeteReturn = regBean.regWechate;
                                    MemberInfo.Instance.templeteTransfer = regBean.regWechate;
                                    StoParams.Instance.regCode = regBean.regSiteCode;
                                    StoParams.Instance.register_networkId = regBean.regSiteID;
                                    StoParams.Instance.register_site = regBean.regSiteName;
                                    regBean.isAnthorized = true;

                                    findMapNet = true;
                                    StoParams.Instance.htDifferentSiteBarcodeInfo[pickNetName] = wayBills;
                                    //pickNetName = realPickNetworkName;
                                    if (findMapNet)
                                    {
                                        if (totalQueryCount % 20 == 0)
                                        {
                                            continue;
                                        }
                                        else
                                        {
                                            break;
                                        }

                                    }
                                }
                                else
                                {
                                    if (res.Contains("未经授权"))
                                    {
                                        regBean.isAnthorized = false;
                                        regBean.dtLimitTime = System.DateTime.Now;
                                        if (!pickNetName.Contains(pickNetName))
                                        {
                                            pickNetName = pickNetName + "未经授权";
                                        }


                                    }
                                    //StoParams.Instance.resMsg = res;
                                }

                            }
                            //RegBean regBean = StoParams.Instance.htRegInfo[realPickNetworkName] as RegBean;


                        }
                        else
                        {
                            //pickNetName = realPickNetworkName;
                        }


                    }


                }
                if (res.Contains("未经授权"))
                {
                    bool findUseFul = false;
                    foreach (DictionaryEntry de in StoParams.Instance.htRegInfo)
                    {
                        if (findUseFul)
                        {
                            break;
                        }
                        ArrayList arListRegBeans = (ArrayList)de.Value;
                        //RegBean regBean = (RegBean)de.Value;
                        foreach (RegBean regBean in arListRegBeans)
                        {
                            string crures = HttpClient.HttpUtil.Instance.PostCommonByToken(strUrl, postData, "trackingExpress", regBean.token);
                            if (crures.Contains("data") && crures.Contains("成功"))
                            {
                                MemberInfo.Instance.token = regBean.token;
                                MemberInfo.Instance.templeteAssign = regBean.regWechate;
                                MemberInfo.Instance.templeteCuijian = regBean.regWechate;
                                MemberInfo.Instance.templeteQS = regBean.regWechate;
                                MemberInfo.Instance.templeteReturn = regBean.regWechate;
                                MemberInfo.Instance.templeteTransfer = regBean.regWechate;
                                StoParams.Instance.regCode = regBean.regSiteCode;
                                StoParams.Instance.register_networkId = regBean.regSiteID;
                                StoParams.Instance.register_site = regBean.regSiteName;
                                findUseFul = true;
                                break;
                            }
                        }


                    }
                }



            }
            catch (Exception ex)
            {
                StoParams.Instance.resMsg = "没有 找到匹配的网点" + ex.ToString();
            }
            return findMapNet;

        }



        public bool resetToken2Win(string wayBills, out string pickNetName, out string orderSource, out string curPickSiteToken, out string customerName)
        {
            bool findMapNet = false;
            pickNetName = "";
            orderSource = "";
            curPickSiteToken = "";
            customerName = "";
            try
            {
                JObject jObjDetail = new JObject();
                jObjDetail["waybillNo"] = wayBills;
                jObjDetail["countryId"] = "1";

                string strUrl = "https://wdgw.jtexpress.com.cn/ops/wdbutler/order/getOrderDetail";

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObjDetail);
                string res = HttpClient.HttpUtil.Instance.PostCommon(strUrl, postData, "trackingExpress");
                totalQueryCount++;
                if (res.Contains("data"))
                {
                    JObject jsonObj = (JObject)JsonConvert.DeserializeObject(res);
                    JObject dataArr = (JObject)jsonObj["data"];
                    if (dataArr != null)
                    {
                        JObject detailsRecords = (JObject)dataArr["details"];
                        string pickNetworkName = detailsRecords["pickNetworkName"].ToString();

                        string realPickNetworkName = detailsRecords["realPickNetworkName"].ToString();



                        if (detailsRecords["orderSourceName"] != null)
                        {
                            orderSource = detailsRecords["orderSourceName"].ToString();
                        }

                        if (detailsRecords["customerName"] != null)
                        {
                            customerName = detailsRecords["customerName"].ToString();
                        }


                        if (pickNetworkName == "")
                        {
                            ArrayList arListAllGXTask3 = new ArrayList();
                            string httpRes3 = "";
                            ArrayList arListRoadMap3 = JTDelayHelper.Instance.getRoadMap(wayBills, out httpRes3, arListAllGXTask3);
                            pickNetworkName = JTDelayHelper.Instance.getLanShouSite(arListRoadMap3);
                        }
                        if (pickNetworkName != "")
                        {
                            pickNetName = pickNetworkName;
                        }

                        if (realPickNetworkName == "")
                        {
                            ArrayList arListAllGXTask3 = new ArrayList();
                            string httpRes3 = "";
                            ArrayList arListRoadMap3 = JTDelayHelper.Instance.getRoadMap(wayBills, out httpRes3, arListAllGXTask3);
                            realPickNetworkName = JTDelayHelper.Instance.getLanShouSite(arListRoadMap3);
                        }
                        if (realPickNetworkName != "")
                        {
                            pickNetName = realPickNetworkName;
                        }


                        if (StoParams.Instance.htRegInfo.ContainsKey(pickNetName) || StoParams.Instance.htRegInfo.ContainsKey(pickNetName.Replace("市", "")))
                        {
                            ArrayList arListRegBeans = StoParams.Instance.htRegInfo[pickNetName] as ArrayList;
                            foreach (RegBean regBean in arListRegBeans)
                            {
                                if (regBean.isLimitInterFace)
                                {
                                    DateTime dtNow = System.DateTime.Now;
                                    TimeSpan ts = dtNow - regBean.dtLimitTime;
                                    if (ts.TotalMinutes < 60)
                                    {
                                        continue;
                                    }

                                }

                                else if (!regBean.isAnthorized)
                                {
                                    DateTime dtNow = System.DateTime.Now;
                                    TimeSpan ts = dtNow - regBean.dtAnthorized;
                                    if (ts.TotalMinutes < 10)
                                    {
                                        continue;
                                    }

                                }
                                res = HttpClient.HttpUtil.Instance.PostCommonByToken(strUrl, postData, "trackingExpress", regBean.token);
                                if (res.Contains("data") && res.Contains("成功"))
                                {
                                    curPickSiteToken = regBean.token;
                                    MemberInfo.Instance.token = regBean.token;
                                    MemberInfo.Instance.templeteAssign = regBean.regWechate;
                                    MemberInfo.Instance.templeteCuijian = regBean.regWechate;
                                    MemberInfo.Instance.templeteQS = regBean.regWechate;
                                    MemberInfo.Instance.templeteReturn = regBean.regWechate;
                                    MemberInfo.Instance.templeteTransfer = regBean.regWechate;
                                    StoParams.Instance.regCode = regBean.regSiteCode;
                                    StoParams.Instance.register_networkId = regBean.regSiteID;
                                    StoParams.Instance.register_site = regBean.regSiteName;
                                    StoParams.Instance.register_user = regBean.user;
                                    regBean.isAnthorized = true;

                                    findMapNet = true;
                                    StoParams.Instance.htDifferentSiteBarcodeInfo[pickNetName] = wayBills;
                                    //pickNetName = realPickNetworkName;
                                    if (findMapNet)
                                    {
                                        if (totalQueryCount % 20 == 0)
                                        {
                                            continue;
                                        }
                                        else
                                        {
                                            break;
                                        }

                                    }
                                }
                                else
                                {
                                    if (res.Contains("未经授权"))
                                    {
                                        regBean.isAnthorized = false;
                                        regBean.dtLimitTime = System.DateTime.Now;
                                        if (!pickNetName.Contains(pickNetName))
                                        {
                                            pickNetName = pickNetName + "未经授权";
                                        }


                                    }
                                    //StoParams.Instance.resMsg = res;
                                }

                            }
                            //RegBean regBean = StoParams.Instance.htRegInfo[realPickNetworkName] as RegBean;


                        }
                        else
                        {
                            //pickNetName = realPickNetworkName;
                        }


                    }


                }
                if (res.Contains("未经授权"))
                {
                    bool findUseFul = false;
                    foreach (DictionaryEntry de in StoParams.Instance.htRegInfo)
                    {
                        if (findUseFul)
                        {
                            break;
                        }
                        ArrayList arListRegBeans = (ArrayList)de.Value;
                        //RegBean regBean = (RegBean)de.Value;
                        foreach (RegBean regBean in arListRegBeans)
                        {
                            string crures = HttpClient.HttpUtil.Instance.PostCommonByToken(strUrl, postData, "trackingExpress", regBean.token);
                            if (crures.Contains("data") && crures.Contains("成功"))
                            {
                                MemberInfo.Instance.token = regBean.token;
                                MemberInfo.Instance.templeteAssign = regBean.regWechate;
                                MemberInfo.Instance.templeteCuijian = regBean.regWechate;
                                MemberInfo.Instance.templeteQS = regBean.regWechate;
                                MemberInfo.Instance.templeteReturn = regBean.regWechate;
                                MemberInfo.Instance.templeteTransfer = regBean.regWechate;
                                StoParams.Instance.regCode = regBean.regSiteCode;
                                StoParams.Instance.register_networkId = regBean.regSiteID;
                                StoParams.Instance.register_site = regBean.regSiteName;
                                findUseFul = true;
                                break;
                            }
                        }


                    }
                }



            }
            catch (Exception ex)
            {
                StoParams.Instance.resMsg = "没有 找到匹配的网点" + ex.ToString();
            }
            return findMapNet;

        }



        public bool resetJmsToken(string wayBills, out string pickNetName, out string orderSource, out string curPickSiteToken, out string customerName)
        {
            bool findMapNet = false;
            pickNetName = "";
            orderSource = "";
            curPickSiteToken = "";
            customerName = "";
            try
            {
                JObject jObjDetail = new JObject();
                jObjDetail["waybillNo"] = wayBills;
                jObjDetail["countryId"] = "1";

                string strUrl = "https://jmsgw.jtexpress.com.cn/operatingplatform/order/getOrderDetail";

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObjDetail);
                string res = HttpClient.HttpUtil.Instance.PostCommon(strUrl, postData, "trackingExpress");
                totalQueryCount++;
                if (res.Contains("data"))
                {
                    JObject jsonObj = (JObject)JsonConvert.DeserializeObject(res);
                    JObject dataArr = (JObject)jsonObj["data"];
                    if (dataArr != null)
                    {
                        JObject detailsRecords = (JObject)dataArr["details"];
                        string pickNetworkName = detailsRecords["pickNetworkName"].ToString();

                        string realPickNetworkName = detailsRecords["realPickNetworkName"].ToString();



                        if (detailsRecords["orderSourceName"] != null)
                        {
                            orderSource = detailsRecords["orderSourceName"].ToString();
                        }

                        if (detailsRecords["customerName"] != null)
                        {
                            customerName = detailsRecords["customerName"].ToString();
                        }


                        if (pickNetworkName == "")
                        {
                            ArrayList arListAllGXTask3 = new ArrayList();
                            string httpRes3 = "";
                            ArrayList arListRoadMap3 = JTDelayHelper.Instance.getRoadMap(wayBills, out httpRes3, arListAllGXTask3);
                            pickNetworkName = JTDelayHelper.Instance.getLanShouSite(arListRoadMap3);
                        }
                        if (pickNetworkName != "")
                        {
                            pickNetName = pickNetworkName;
                        }

                        if (realPickNetworkName == "")
                        {
                            ArrayList arListAllGXTask3 = new ArrayList();
                            string httpRes3 = "";
                            ArrayList arListRoadMap3 = JTDelayHelper.Instance.getRoadMap(wayBills, out httpRes3, arListAllGXTask3);
                            realPickNetworkName = JTDelayHelper.Instance.getLanShouSite(arListRoadMap3);
                        }
                        if (realPickNetworkName != "")
                        {
                            pickNetName = realPickNetworkName;
                        }


                        if (StoParams.Instance.htRegInfo.ContainsKey(pickNetName) || StoParams.Instance.htRegInfo.ContainsKey(pickNetName.Replace("市", "")))
                        {
                            ArrayList arListRegBeans = StoParams.Instance.htRegInfo[pickNetName] as ArrayList;
                            foreach (RegBean regBean in arListRegBeans)
                            {
                                if (regBean.isLimitInterFace)
                                {
                                    DateTime dtNow = System.DateTime.Now;
                                    TimeSpan ts = dtNow - regBean.dtLimitTime;
                                    if (ts.TotalMinutes < 60)
                                    {
                                        continue;
                                    }

                                }

                                else if (!regBean.isAnthorized)
                                {
                                    DateTime dtNow = System.DateTime.Now;
                                    TimeSpan ts = dtNow - regBean.dtAnthorized;
                                    if (ts.TotalMinutes < 10)
                                    {
                                        continue;
                                    }

                                }
                                res = HttpClient.HttpUtil.Instance.PostCommonByToken(strUrl, postData, "trackingExpress", regBean.token);
                                if (res.Contains("data") && res.Contains("成功"))
                                {
                                    curPickSiteToken = regBean.token;
                                    MemberInfo.Instance.token = regBean.token;
                                    MemberInfo.Instance.templeteAssign = regBean.regWechate;
                                    MemberInfo.Instance.templeteCuijian = regBean.regWechate;
                                    MemberInfo.Instance.templeteQS = regBean.regWechate;
                                    MemberInfo.Instance.templeteReturn = regBean.regWechate;
                                    MemberInfo.Instance.templeteTransfer = regBean.regWechate;
                                    StoParams.Instance.regCode = regBean.regSiteCode;
                                    StoParams.Instance.register_networkId = regBean.regSiteID;
                                    StoParams.Instance.register_site = regBean.regSiteName;
                                    StoParams.Instance.register_user = regBean.user;
                                    regBean.isAnthorized = true;

                                    findMapNet = true;
                                    StoParams.Instance.htDifferentSiteBarcodeInfo[pickNetName] = wayBills;
                                    //pickNetName = realPickNetworkName;
                                    if (findMapNet)
                                    {
                                        if (totalQueryCount % 20 == 0)
                                        {
                                            continue;
                                        }
                                        else
                                        {
                                            break;
                                        }

                                    }
                                }
                                else
                                {
                                    if (res.Contains("未经授权"))
                                    {
                                        regBean.isAnthorized = false;
                                        regBean.dtLimitTime = System.DateTime.Now;
                                        if (!pickNetName.Contains(pickNetName))
                                        {
                                            pickNetName = pickNetName + "未经授权";
                                        }


                                    }
                                    //StoParams.Instance.resMsg = res;
                                }

                            }
                            //RegBean regBean = StoParams.Instance.htRegInfo[realPickNetworkName] as RegBean;


                        }
                        else
                        {
                            //pickNetName = realPickNetworkName;
                        }


                    }


                }
                if (res.Contains("未经授权"))
                {
                    bool findUseFul = false;
                    foreach (DictionaryEntry de in StoParams.Instance.htRegInfo)
                    {
                        if (findUseFul)
                        {
                            break;
                        }
                        ArrayList arListRegBeans = (ArrayList)de.Value;
                        //RegBean regBean = (RegBean)de.Value;
                        foreach (RegBean regBean in arListRegBeans)
                        {
                            string crures = HttpClient.HttpUtil.Instance.PostCommonByToken(strUrl, postData, "trackingExpress", regBean.token);
                            if (crures.Contains("data") && crures.Contains("成功"))
                            {
                                MemberInfo.Instance.token = regBean.token;
                                MemberInfo.Instance.templeteAssign = regBean.regWechate;
                                MemberInfo.Instance.templeteCuijian = regBean.regWechate;
                                MemberInfo.Instance.templeteQS = regBean.regWechate;
                                MemberInfo.Instance.templeteReturn = regBean.regWechate;
                                MemberInfo.Instance.templeteTransfer = regBean.regWechate;
                                StoParams.Instance.regCode = regBean.regSiteCode;
                                StoParams.Instance.register_networkId = regBean.regSiteID;
                                StoParams.Instance.register_site = regBean.regSiteName;
                                findUseFul = true;
                                break;
                            }
                        }


                    }
                }



            }
            catch (Exception ex)
            {
                StoParams.Instance.resMsg = "没有 找到匹配的网点" + ex.ToString();
            }
            return findMapNet;

        }

        public bool resetToken(string wayBills,out string pickNetName,out string orderSource,out string curPickSiteToken,out string customerName)
        {
            bool res = false;
            if(StoParams.Instance.isRabbitWin)
            {
                res=resetToken2Win(wayBills, out pickNetName, out orderSource, out curPickSiteToken, out customerName);
            }
            else
            {
                res=resetJmsToken(wayBills, out pickNetName, out orderSource, out curPickSiteToken, out customerName);
            }
            return res;

        }


        public bool isContainZCFJNext(int curIndex,string curSite,ArrayList arListRoadBean)
        {
            bool res = false;
            try
            {
                for(int i= curIndex+1; i< arListRoadBean.Count;i++)
                {
                    RoadBean rd = (RoadBean)arListRoadBean[i];
                    if(rd.scanNetworkName== curSite&& rd.scanTypeName.Contains("发件"))
                    {
                        res = true;
                    }
                }
            }
            catch(Exception ex)
            {

            }
            return res;
                
                
        }

        public string getResponse(ArrayList arListBarcodes,Hashtable htRes)
        {
            StringBuilder sb = new StringBuilder();
            string res = "";
            try
            {
                ArrayList arListResType = new ArrayList();
                foreach(string strBarcode in arListBarcodes)
                {
                    //logHelp.LogHelper.Instance.writeLog("strBarcode=" + strBarcode);
                    if(htRes.ContainsKey(strBarcode))
                    {
                        string response = htRes[strBarcode].ToString();

                        //logHelp.LogHelper.Instance.writeLog("response=" + response);
                        if (!arListResType.Contains(response))
                        {
                            arListResType.Add(response);
                        }
                    }
                }

                foreach(string strType in arListResType)
                {
                   
                    foreach(string strBarcode in arListBarcodes)
                    {
                        
                        if(htRes.ContainsKey(strBarcode)&& !res.Contains(strBarcode)&& (htRes[strBarcode].ToString()==strType))
                        {
                            res = res + strBarcode + "\r\n";
                            htRes.Remove(strBarcode);
                            if (strType.Contains("后续跟踪"))
                            {
                                sb.AppendLine(strBarcode);
                            }
                        }
                    }
                    string restrType = strType.Replace("\r\n", ",");
                    res = res + restrType + "\r\n";
                }
                if(res.EndsWith("\r\n"))
                {
                    res = res.TrimEnd('\n');
                    res = res.TrimEnd('\r');
                }
                if(sb.ToString().Length>10)
                {
                    //string barcodeNomap = sb.ToString().TrimEnd(new char[] { '\r', '\n' });
                    logHelp.LogHelper.Instance.writeNoRoadMapBarcode(sb.ToString());
                }
            }
            catch(Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog("getResponse ex:"+ex.ToString());
            }
            return res;

        }




        public bool getUserMsg(string barcode, CustomerBean customerBean,string token,out bool isFindreverse,out bool isOverCount)
        {
            isFindreverse = false;
            isOverCount = false;
            bool res = false;
            try
            {
                string strQueryUrl = "https://jmsgw.jtexpress.com.cn/sqsthird/thirdService/waybill/commonWaybillListByWaybillNos?waybillNos=" + barcode;
                if(StoParams.Instance.isRabbitWin)
                {
                    strQueryUrl = "https://wdgw.jtexpress.com.cn/sqsthird/thirdService/waybill/commonWaybillListByWaybillNos?waybillNos=" + barcode;
                }
                JObject jObj = new JObject(); ;

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string resMsg = HttpClient.HttpUtil.Instance.QueryCommonByToekn(strQueryUrl, postData, "GET", "integratedComprehensive", token);
                if (!resMsg.Contains("请求成功"))
                {
                    return false;
                }

                JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(resMsg);
                //JObject dataObj = (JObject)jsonObjRes["data"];
                JArray records = (JArray)jsonObjRes["data"];
                if (records.Count == 0)
                {
                    return false;
                }

                JObject detailObj = (JObject)records[0];
                string receiverProvinceName = detailObj["receiverProvinceName"].ToString();
                string receiverCityName = detailObj["receiverCityName"].ToString();
                string receiverAreaName = detailObj["receiverAreaName"].ToString();
                string receiverDetailedAddress = detailObj["receiverDetailedAddress"].ToString();

                string receiverName = detailObj["receiverName"].ToString();
                JToken receiverMobilePhoneJtoken = (JToken)detailObj["receiverMobilePhone"];
                string receiverMobilePhone = "";
                if (receiverMobilePhoneJtoken != null)
                {
                    receiverMobilePhone = receiverMobilePhoneJtoken.ToString();
                }

                strQueryUrl = "https://jmsgw.jtexpress.com.cn/sqsthird/integration/getWaybillsByReverse?waybillId=" + barcode + "&queryReason=KFLD";
                if(StoParams.Instance.isRabbitWin)
                {
                    strQueryUrl = "https://wdgw.jtexpress.com.cn/sqsthird/integration/getWaybillsByReverse?waybillId=" + barcode + "&queryReason=KFLD";
                }

                jObj = new JObject(); ;

                postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                resMsg = HttpClient.HttpUtil.Instance.QueryCommonByToekn(strQueryUrl, postData, "GET", "integratedComprehensive",token);
                if(!resMsg.Contains("反查时间")&& !resMsg.Contains("超出当日"))
                {
                    isFindreverse = true;
                    jsonObjRes = (JObject)JsonConvert.DeserializeObject(resMsg);
                    if (!resMsg.Contains("结果为空"))
                    {
                        JObject dataObj = (JObject)jsonObjRes["data"];
                        receiverName = dataObj["receiverName"].ToString();

                        JToken receiverMobileTelphone = (JToken)dataObj["receiverMobilePhone"];
                        if (receiverMobilePhone.Contains("*"))
                        {
                            if(receiverMobileTelphone!=null&& receiverMobileTelphone.ToString().Length>5)
                            {
                                receiverMobilePhone = receiverMobileTelphone.ToString();
                            }
                        }


                        JToken receiverTelphone = (JToken)dataObj["receiverTelphone"];

                        JToken virtualNumber = (JToken)dataObj["virtualNumber"];
                        if (receiverMobilePhone.Contains("*"))
                        {
                            if (receiverTelphone != null && !receiverTelphone.ToString().Contains("*")&& receiverTelphone.ToString().Length>5)
                            {
                                receiverMobilePhone = receiverTelphone.ToString();
                            }
                            else
                            {
                                if (virtualNumber != null && !virtualNumber.ToString().Contains("*") && virtualNumber.ToString().Length > 5)
                                {
                                    receiverMobilePhone = virtualNumber.ToString();
                                }
                            }
                        }



                    }
                }
                else if(resMsg.Contains("超出当日"))
                {

                    logHelp.LogHelper.Instance.writeLog("查询电联失败 "+ resMsg);
                    isOverCount = true;
                    return res;
                }
                
                
                
                customerBean.receiverMobilePhone = receiverMobilePhone;
                customerBean.receiverName = receiverName;
                customerBean.receiverProvinceName = receiverProvinceName;
                customerBean.receiverCityName = receiverCityName;
                customerBean.receiverAreaName = receiverAreaName;
                customerBean.receiverDetailedAddress = receiverDetailedAddress;
                //parcel.addr = "客户信息:" + receiverName + " 电话：" + receiverMobilePhone + " " + receiverProvinceName + receiverCityName + receiverAreaName + " " + receiverDetailedAddress;
                //parcel.ori_addr = parcel.addr;
                res = true;





            }
            catch (Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog(" getUserMsg ex: " + ex.ToString());
            }
            return res;

        }
        public bool getUserMsgForBoard(string barcode, CustomerBean customerBean,string token)
        {
   
            bool res = false;
            try
            {
                string strQueryUrl = "https://jmsgw.jtexpress.com.cn/sqsthird/thirdService/waybill/commonWaybillListByWaybillNos?waybillNos=" + barcode;
                if(StoParams.Instance.isRabbitWin)
                {
                    strQueryUrl = "https://wdgw.jtexpress.com.cn/sqsthird/thirdService/waybill/commonWaybillListByWaybillNos?waybillNos=" + barcode;
                }
                JObject jObj = new JObject(); ;

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string resMsg = HttpClient.HttpUtil.Instance.QueryCommonByToekn(strQueryUrl, postData, "GET", "integratedComprehensive", token);
                if (!resMsg.Contains("请求成功"))
                {
                    return false;
                }

                JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(resMsg);
                //JObject dataObj = (JObject)jsonObjRes["data"];
                JArray records = (JArray)jsonObjRes["data"];
                if (records.Count == 0)
                {
                    return false;
                }

                JObject detailObj = (JObject)records[0];
                string receiverProvinceName = detailObj["receiverProvinceName"].ToString();
                string receiverCityName = detailObj["receiverCityName"].ToString();
                string receiverAreaName = detailObj["receiverAreaName"].ToString();
                string receiverDetailedAddress = detailObj["receiverDetailedAddress"].ToString();

                string receiverName = detailObj["receiverName"].ToString();
                JToken receiverMobilePhoneJtoken = (JToken)detailObj["receiverMobilePhone"];
                string receiverMobilePhone = "";
                if (receiverMobilePhoneJtoken != null)
                {
                    receiverMobilePhone = receiverMobilePhoneJtoken.ToString();
                }

                /*strQueryUrl = "https://jmsgw.jtexpress.com.cn/sqsthird/integration/getWaybillsByReverse?waybillId=" + barcode + "&queryReason=KFLD";

                jObj = new JObject(); ;

                postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                resMsg = HttpClient.HttpUtil.Instance.QueryCommon(strQueryUrl, postData, "GET", "integratedComprehensive");
                if (!resMsg.Contains("反查时间"))
                {
                    
                    jsonObjRes = (JObject)JsonConvert.DeserializeObject(resMsg);
                    if (!resMsg.Contains("结果为空"))
                    {
                        JObject dataObj = (JObject)jsonObjRes["data"];
                        receiverName = dataObj["receiverName"].ToString();

                        JToken receiverMobileTelphone = (JToken)dataObj["receiverMobilePhone"];
                        if (receiverMobilePhone.Contains("*"))
                        {
                            if (receiverMobileTelphone != null && receiverMobileTelphone.ToString().Length > 5)
                            {
                                receiverMobilePhone = receiverMobileTelphone.ToString();
                            }
                        }


                        JToken receiverTelphone = (JToken)dataObj["receiverTelphone"];

                        JToken virtualNumber = (JToken)dataObj["virtualNumber"];
                        if (receiverMobilePhone.Contains("*"))
                        {
                            if (receiverTelphone != null && !receiverTelphone.ToString().Contains("*") && receiverTelphone.ToString().Length > 5)
                            {
                                receiverMobilePhone = receiverTelphone.ToString();
                            }
                            else
                            {
                                if (virtualNumber != null && !virtualNumber.ToString().Contains("*") && virtualNumber.ToString().Length > 5)
                                {
                                    receiverMobilePhone = virtualNumber.ToString();
                                }
                            }
                        }



                    }
                }*/



                customerBean.receiverMobilePhone = receiverMobilePhone;
                customerBean.receiverName = receiverName;
                customerBean.receiverProvinceName = receiverProvinceName;
                customerBean.receiverCityName = receiverCityName;
                customerBean.receiverAreaName = receiverAreaName;
                customerBean.receiverDetailedAddress = receiverDetailedAddress;
                //parcel.addr = "客户信息:" + receiverName + " 电话：" + receiverMobilePhone + " " + receiverProvinceName + receiverCityName + receiverAreaName + " " + receiverDetailedAddress;
                //parcel.ori_addr = parcel.addr;
                res = true;





            }
            catch (Exception ex)
            {

            }
            return res;

        }
        public bool getUserMsg(string barcode,ParcelBean parcel)
        {
            bool res = false;
            try
            {
                string strQueryUrl = "https://jmsgw.jtexpress.com.cn/sqsthird/thirdService/waybill/commonWaybillListByWaybillNos?waybillNos=" + barcode;

                if(StoParams.Instance.isRabbitWin)
                {
                    strQueryUrl = "https://wdgw.jtexpress.com.cn/sqsthird/thirdService/waybill/commonWaybillListByWaybillNos?waybillNos=" + barcode;
                }
                JObject jObj = new JObject();;

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string resMsg = HttpClient.HttpUtil.Instance.QueryCommon(strQueryUrl, postData, "GET", "integratedComprehensive");
                if (!resMsg.Contains("请求成功"))
                {
                    return false;
                }

                JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(resMsg);
                //JObject dataObj = (JObject)jsonObjRes["data"];
                JArray records = (JArray)jsonObjRes["data"];
                if (records.Count == 0)
                {
                    return false;
                }

                JObject detailObj = (JObject)records[0];
                string receiverProvinceName = detailObj["receiverProvinceName"].ToString();
                string receiverCityName = detailObj["receiverCityName"].ToString();
                string receiverAreaName = detailObj["receiverAreaName"].ToString();
                string receiverDetailedAddress = detailObj["receiverDetailedAddress"].ToString();


                strQueryUrl = "https://jmsgw.jtexpress.com.cn/sqsthird/integration/getWaybillsByReverse?waybillId="+ barcode +"&queryReason=KFLD";
                if (StoParams.Instance.isRabbitWin)
                {
                    strQueryUrl = "https://wdgw.jtexpress.com.cn/sqsthird/integration/getWaybillsByReverse?waybillId="+ barcode + "&queryReason=KFLD" ;
                }


                jObj = new JObject(); ;

                postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                resMsg = HttpClient.HttpUtil.Instance.QueryCommon(strQueryUrl, postData, "GET", "integratedComprehensive");

                jsonObjRes = (JObject)JsonConvert.DeserializeObject(resMsg);
                JObject dataObj = (JObject)jsonObjRes["data"];
                string receiverName= dataObj["receiverName"].ToString();

                string receiverMobilePhone = dataObj["receiverMobilePhone"].ToString();

                JToken receiverTelphone = (JToken)dataObj["receiverTelphone"];

                JToken virtualNumber = (JToken)dataObj["virtualNumber"];
                if(receiverMobilePhone.Contains("*"))
                {
                    if(receiverTelphone!=null&& !receiverTelphone.ToString().Contains("*")&& receiverTelphone.ToString().Length>5)
                    {
                        receiverMobilePhone = receiverTelphone.ToString();
                    }
                    else
                    {
                        if (virtualNumber != null && !virtualNumber.ToString().Contains("*")&& virtualNumber.ToString().Length > 5)
                        {
                            receiverMobilePhone = virtualNumber.ToString();
                        }
                    }
                }

                if (receiverMobilePhone.Contains("*"))
                {
                    return false;
                }
                parcel.phoneNumList.Add(receiverMobilePhone);
                parcel.addr = "客户信息:" + receiverName + " 电话：" + receiverMobilePhone + " " + receiverProvinceName + receiverCityName + receiverAreaName + " " + receiverDetailedAddress;
                parcel.ori_addr = parcel.addr;
                res = true;





            }
            catch(Exception ex)
            {

            }
            return res;
            
        }



        

        public string getLeaveMsgResponse(ArrayList arListRoadMap, string commandType,ParcelBean parcelBean,bool isYiqingDelay)
        {
            string res = "以上单号已联系网点催促";
            try
            {
                string lastStatus = getLastParCelStatus(arListRoadMap);
                if (commandType=="改电话")
                {
                    parcelBean.replyType = "改电话";
                    res = "已通知网点修改";
                    if(StoParams.Instance.register_site.Contains("曹三")|| StoParams.Instance.register_site.Contains("菊城"))
                    {
                        res = "以上单号已登记修改";
                    }
                }
                else if(parcelBean.ori_addr.Length>1&&(parcelBean.ori_addr.Replace(" ","").Contains("短少")|| parcelBean.ori_addr.Replace(" ", "").Contains("破损")))
                {
                    parcelBean.replyType = "破损";
                    res = "已通知相关网点核实处理，破损件需在签收日期三天内提供相应材料（带有单号的外包装破损图片、内物破损图片、包装内填充物图片以及交易截图、短少或破损内物价值截图）----------以便后续申请理赔 未提供无法受理请知悉";
                    if(StoParams.Instance.register_site.Contains("曹三")|| StoParams.Instance.register_site.Contains("菊城"))
                    {
                        res = "已通知相关网点核实处理，破损件需在签收日期三天内提供相应材料（面单图片、内物短少/破损图片、价值截图）麻烦贵司提供并告知我司损失金额，以便后续申请理赔，未提供无法受理哈";
                    }
                   
                }
                else if (parcelBean.ori_addr.Contains("规范拦截未退回"))
                {
                    res = "以上单号已通知责任网点核实";
                }
                else if ((parcelBean.ori_addr.Length < 6)&&( parcelBean.ori_addr.Replace(" ", "").Contains("催件") || parcelBean.ori_addr.Replace(" ", "").Contains("催促") || parcelBean.ori_addr.Replace(" ", "").Contains("催货") || parcelBean.ori_addr.Replace(" ","").Contains("催派")))
                {
                    if (commandType.Contains("签收"))
                    {
                        res = "以上单号显示已签收，已通知网点核实是否派送成功，如已申请退款，请先不要处理售后，48小时后无处理结果再处理售后，谢谢，麻烦下次携带收件人信息电话等联系方式信息，以便后续跟踪。";
                        if (StoParams.Instance.register_site.Contains("曹三") || StoParams.Instance.register_site.Contains("菊城"))
                        {
                            res = "以上单号显示已签收，已通知网点核实是否派送成功";
                        }
                    }
                    else
                    {
                        res = "以上单号已联系网点催促，麻烦下次携带收件人信息电话等联系方式信息，以便后续跟踪。";
                        if(StoParams.Instance.register_site.Contains("凤岗") || StoParams.Instance.register_site.Contains("电子"))
                        {
                            if (lastStatus.Contains("出仓"))
                            {
                                res = "已催促，请耐心等待，后续跟进处理(查件请提供客户姓名电话和详细地址，谢谢)";
                            }
                            if (lastStatus.Contains("入库"))
                            {
                                res = "已派送至待收点暂存，待客户取件，已催促派件网点联系处理(查件请提供客户姓名电话和详细地址，谢谢)";
                            }
                        }
                        if (StoParams.Instance.register_site.Contains("曹三") || StoParams.Instance.register_site.Contains("菊城"))
                        {
                            res = "以上单号已联系网点催促，麻烦下次携带收件人信息电话等联系方式信息，以便后续跟踪哦";
                        }
                        



                    }
                        
                }
                else
                {
                  
                    
                    if (commandType.Contains("签收"))
                    {
                        parcelBean.replyType = "签收未收到";
                        res = "以上单号已通知派件站点核实签收，\r\n要是后期客户再次反馈未收到，麻烦再次通知我司跟进升级处理";
                        if (StoParams.Instance.register_site.Contains("曹三") || StoParams.Instance.register_site.Contains("菊城"))
                        {
                            res = "以上单号已通知派件站点核实签收，如后期客户反馈未收到，麻烦再次通知我司跟进升级处理，谢谢";
                        }
                        if(StoParams.Instance.register_site.Contains("凤岗")|| StoParams.Instance.register_site.Contains("电子"))
                        {
                            if(parcelBean.ori_addr.Contains("签收")&& parcelBean.ori_addr.Contains("收到"))
                            {
                                res = "以上单号已通知派件站点核实签收，麻烦提供收件人反馈未收到的聊天截图跟交易截图(如已提供请忽略)";
                            }
                        }


                    }
                    else if (commandType.Contains("延误查件"))
                    {
                        parcelBean.replyType = "延误查件";
                        res = "以上单号已留言站点核实";
                    }
                    else
                    {
                        res = "已通知核实！！";
                        if (StoParams.Instance.register_site.Contains("凤岗")|| StoParams.Instance.register_site.Contains("电子"))
                        {
                            if (lastStatus.Contains("出仓"))
                            {
                                if (parcelBean.phoneNumList.Count > 0)
                                {
                                    res = "已催促，请耐心等待，后续跟进处理";
                                }
                                else
                                {
                                    res = "已催促，请耐心等待，后续跟进处理,查件请提供收件人信息";
                                }

                                    
                            }
                            if (lastStatus.Contains("入库"))
                            {
                                if (parcelBean.phoneNumList.Count > 0)
                                {
                                    res = "已派送至待收点暂存，待客户取件，已催促派件网点联系处理";
                                }
                                else
                                {
                                    res = "已派送至待收点暂存，待客户取件，已催促派件网点联系处理,查件请提供收件人信息";
                                }
                                    
                            }
                        }

                        if (StoParams.Instance.register_site.Contains("曹三") || StoParams.Instance.register_site.Contains("菊城"))
                        {
                            if(parcelBean.phoneNumList.Count>0)
                            {
                                res = "以上单号已通知核实";
                            }
                            else
                            {
                                res = "以上单号已联系网点催促，麻烦下次携带收件人名字+电话，以便后续跟踪哦";
                            }
                            
                        }

                    }
                }
                int hour = 0;
                string msg = "";

                SiteBean siteBean = new SiteBean();
                if(!commandType.Contains("破损"))
                {
                    if (StoParams.Instance.register_site.Contains("邓岗")|| StoParams.Instance.register_site.Contains("水洲"))
                    {
                        if (isRoadMapStopTooLong(arListRoadMap, out hour, out msg))
                        {
                            res = msg;
                        }
                        else if (isLastRoadMapIsProblem(arListRoadMap, siteBean, out msg))
                        {
                            res = msg;
                        }
                    }
                }
                      
                
            }
            catch (Exception ex)
            {

            }
            return res;

        }


        public ParcelBean getInterceptParcel(ParcelBean parcelBean)
        {
            ParcelBean parcel = new ParcelBean();
            try
            {
                parcel.wayBill = parcelBean.wayBill;
                parcel.addr = parcelBean.addr;
                parcel.customerName = parcelBean.customerName;
                parcel.dtToDoTaskTime = parcelBean.dtToDoTaskTime;
                parcel.fromWxID = parcelBean.fromWxID;
                parcel.roomID = parcelBean.roomID;
                parcel.senderWeChat = parcelBean.senderWeChat;
                parcel.wechat = parcelBean.wechat;
                parcel.ori_addr = parcelBean.ori_addr;
                parcel.isSuperWay = parcelBean.isSuperWay;
                parcel.taskType = "拦截";
                parcel.isCancelOrder = true;
            }
            catch(Exception ex)
            {

            }
            return parcel;


        }

       
        public bool isRoadMapStopTooLong(ArrayList arListRoadMap,out int hour,out string msg)
        {
            hour = 0;
            bool res = false;
            msg = "";
            try
            {
                string curRoadStatus = "";
                RoadBean road = new RoadBean();
                for (int i= arListRoadMap.Count-1;i>0; i--)
                {
                    road = (RoadBean)arListRoadMap[i];
                    if(road.scanNetworkName!=StoParams.Instance.register_site)
                    {
                        break;
                        
                    }
                }
                string scanTypeName = road.scanTypeName;
                string scanTime = road.scanTime;
                curRoadStatus = road.scanTypeName;
                TimeSpan ts = System.DateTime.Now - Convert.ToDateTime(scanTime);
                if (ts.TotalHours < 48)
                {
                    return false;
                }
                hour = (int)ts.TotalHours;
                if (scanTypeName == "问题件扫描")
                {
                    curRoadStatus = road.waybillTrackingContent;
                    curRoadStatus = curRoadStatus.Substring(curRoadStatus.LastIndexOf("问题件原因") + 5);
                    curRoadStatus = curRoadStatus.Replace("【", "");
                    curRoadStatus = curRoadStatus.Replace("】", "");
                    curRoadStatus = curRoadStatus.Trim();
                    
                }

                int day = (hour / 24);
                int leftHour = (hour % 24);
                string content = day + "天";
                if(leftHour>0)
                {
                    content = content + leftHour + "小时";
                }


                if (curRoadStatus!="")
                {
                    string admsg = "核实处理";
                    if (road.waybillTrackingContent.Contains("签收"))
                    {
                        admsg = "核实签收";
                    }
                    msg = "已通知相关网点"+ admsg + "，物流停滞" + content + ", 物流显示" + curRoadStatus+", 当前网点："+ road.scanNetworkName+ "";
                    res = true;
                }
                

            }
            catch(Exception ex)
            {

            }
            return res;
        }


        public void initLanshouWechatDir()
        {
            try
            {
                string wechatFileDir = ConfigurationManager.AppSettings["wechatFileDir"];

                string yearDate = System.DateTime.Now.ToString("yyyy-MM");
                //StoParams.Instance.wechatGroupFileDir = wechatFileDir+ yearDate+@"\";
                StoParams.Instance.wechatGroupFileDir = wechatFileDir + yearDate;
            }
            catch (Exception ex)
            {

            }
        }


        public void initLanshouScanUrl()
        {
            try
            {
                string scanUrl = ConfigurationManager.AppSettings["jmsScanUrl"];
                StoParams.Instance.scanUrl = scanUrl;
            }
            catch (Exception ex)
            {

            }
        }

        


        public void initLanshouToken()
        {
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.TokenLanshouPath;
                string res = UtilityHelp.Instance.getLanshouToken(path);
                MemberInfo.Instance.lanshoutoken = res; 
            }
            catch (Exception ex)
            {

            }
        }



        public void initUniqueSiteWechat()
        {
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.UniqueWeChatSitePath;
                ArrayList arListReg = UtilityHelp.Instance.getTokenSiteName(path);
                if (arListReg.Count > 0)
                {
                    foreach (string strLine in arListReg)
                    {
                        if (strLine.Length > 1)
                        {
                            string[] arr = strLine.Split('$');
                            if(arr.Length>1)
                            {
                                StoParams.Instance.htSpecialSiteWechat[arr[0]] = arr[1];
                            }
                            
                        }

                    }
                }
            }
            catch (Exception ex)
            {

            }
        }



        public void initLanshouSiteUrl()
        {
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.LanshouSitePath;
                ArrayList arListReg = UtilityHelp.Instance.getTokenSiteName(path);
                if (arListReg.Count > 0)
                {
                    foreach (string strLine in arListReg)
                    {
                        if (strLine.Length > 1)
                        {
                            string[] arr = strLine.Split('$');
                            if (arr.Length > 1)
                            {
                                StoParams.Instance.htLanshouSiteUrl[arr[0]] = arr[1];
                            }

                        }

                    }
                }
            }
            catch (Exception ex)
            {

            }
        }



        public void resetWechat(ParcelBean parcelBean,string pickName)
        {
            try
            {
                if(StoParams.Instance.htSpecialSiteWechat.ContainsKey(pickName))
                {
                    string wechat = StoParams.Instance.htSpecialSiteWechat[pickName] as string;
                    if(wechat.Length>1)
                    {
                        parcelBean.wechat = wechat;
                    }
                }

            }
            catch(Exception ex)
            {

            }
        }



        public void initSiteWorkOrder()
        {
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.WorkOrderSitePath;
                ArrayList arListReg = UtilityHelp.Instance.getTokenSiteName(path);
                if (arListReg.Count > 0)
                {
                    foreach (string strLine in arListReg)
                    {
                        if (strLine.Length > 3)
                        {
                            string[] arr = strLine.Split(':');

                            WorkOrdrBean workOrderBean = new WorkOrdrBean();
                            string roomID = arr[0];
                            string siteName = arr[1];
                            string fromIDList = arr[2];

                            string ordinaryMinute = arr[3];
                            string platMinute = arr[4];
                            string dispatchMinute = arr[5];

                            string ordinaryHourOverTime = arr[6];
                            string platHourOverTime = arr[7];
                            string dispatchHourOverTime = arr[8];

                            string mentionTime = arr[9];
                            mentionTime = mentionTime.Replace("点", ":");

                            workOrderBean.roomID = roomID;
                            workOrderBean.siteName = siteName.Trim();
                            workOrderBean.mentionUser = fromIDList;
                            
                            if(ordinaryMinute.Contains("-"))
                            {
                                ordinaryMinute = ordinaryMinute.Substring(ordinaryMinute.IndexOf('-') + 1);
                                ordinaryMinute = ordinaryMinute.Replace("minute", "");
                                if(MathUtility.ImpIsNum(ordinaryMinute))
                                {
                                    workOrderBean.ordinayMinute = Convert.ToInt32(ordinaryMinute);
                                }
                                
                            }

                            if (platMinute.Contains("-"))
                            {
                                platMinute = platMinute.Substring(platMinute.IndexOf('-') + 1);
                                platMinute = platMinute.Replace("minute", "");
                                if (MathUtility.ImpIsNum(platMinute))
                                {
                                    workOrderBean.platMinute = Convert.ToInt32(platMinute);
                                }

                            }


                            if (dispatchMinute.Contains("-"))
                            {
                                dispatchMinute = dispatchMinute.Substring(dispatchMinute.IndexOf('-') + 1);
                                dispatchMinute = dispatchMinute.Replace("minute", "");
                                if (MathUtility.ImpIsNum(dispatchMinute))
                                {
                                    workOrderBean.dispatchMinute = Convert.ToInt32(dispatchMinute);
                                }
                            }


                            if (ordinaryHourOverTime.Contains("-"))
                            {
                                ordinaryHourOverTime = ordinaryHourOverTime.Substring(ordinaryHourOverTime.IndexOf('-') + 1);
                                ordinaryHourOverTime = ordinaryHourOverTime.Replace("hour", "");
                                string[] arrHour = ordinaryHourOverTime.Split(',');
                                if (MathUtility.ImpIsNum(arrHour[0]))
                                {
                                    workOrderBean.ordinayOverTimeHour1 = Convert.ToInt32(arrHour[0]);
                                }
                                if(arrHour.Length==2)
                                {
                                    if (MathUtility.ImpIsNum(arrHour[1]))
                                    {
                                        workOrderBean.ordinayOverTimeHour2 = Convert.ToInt32(arrHour[1]);
                                    }
                                }                                

                            }

                            if (platHourOverTime.Contains("-"))
                            {
                                platHourOverTime = platHourOverTime.Substring(platHourOverTime.IndexOf('-') + 1);
                                platHourOverTime = platHourOverTime.Replace("hour", "");
                                string[] arrHour = platHourOverTime.Split(',');
                                if (MathUtility.ImpIsNum(arrHour[0]))
                                {
                                    workOrderBean.platOverTimeHour1 = Convert.ToInt32(arrHour[0]);
                                }
                                if (arrHour.Length == 2)
                                {
                                    if (MathUtility.ImpIsNum(arrHour[1]))
                                    {
                                        workOrderBean.platOverTimeHour2 = Convert.ToInt32(arrHour[1]);
                                    }
                                }

                            }

                            if (dispatchHourOverTime.Contains("-"))
                            {
                                dispatchHourOverTime = dispatchHourOverTime.Substring(dispatchHourOverTime.IndexOf('-') + 1);
                                dispatchHourOverTime = dispatchHourOverTime.Replace("hour", "");
                                string[] arrHour = dispatchHourOverTime.Split(',');
                                if (MathUtility.ImpIsNum(arrHour[0]))
                                {
                                    workOrderBean.dispatchOverTimeHour1 = Convert.ToInt32(arrHour[0]);
                                }
                                if (arrHour.Length == 2)
                                {
                                    if (MathUtility.ImpIsNum(arrHour[1]))
                                    {
                                        workOrderBean.dispatchOverTimeHour2 = Convert.ToInt32(arrHour[1]);
                                    }
                                }

                            }
                            string[] arrMention = mentionTime.Split('-');
                            if(arrMention.Length>1)
                            {
                                workOrderBean.startTime = arrMention[0];

                                workOrderBean.endTime = arrMention[1];
                            }
                            









                            FrameDecoderManager.Instance.htRoomWrokOrder[siteName] = workOrderBean;



                        }

                    }
                }
            }
            catch (Exception ex)
            {

            }
        }



        public void initSiteCustomer()
        {
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.OutboundCustomerSitePath;
                ArrayList arListReg = UtilityHelp.Instance.getTokenSiteName(path);
                if (arListReg.Count > 0)
                {
                    foreach (string strLine in arListReg)
                    {
                        if (strLine.Length > 3)
                        {
                            string[] arr = strLine.Split(':');
                            FrameDecoderManager.Instance.htSiteNameAndRoom[arr[0]] = arr[1];


                        }

                    }
                }
            }
            catch (Exception ex)
            {

            }
        }


        public void initAllOutboundType()
        {
            int curRow = 1;
            try
            {
                string path = System.Environment.CurrentDirectory + "\\" + StoParams.Instance.ProblemAckSitePath;

                LogHelper.Instance.writeLog("初始化完成：path=" + path);

                Worksheet sheet1 = UtilityExcel.Instance.GetWorksheet(path, 0);
                int rowCount = sheet1.Cells.Rows.Count;

                LogHelper.Instance.writeLog("初始化完成：rowcount=" + rowCount.ToString());
                for (int i = 1; i < rowCount; i++)
                {
                    curRow = i;
                    Row row = sheet1.Cells.Rows[i];
                    if (row.IsBlank)
                    {
                        continue;
                    }

                    string problemName = "";
                    if (row[3].Value != null)
                    {
                        problemName = row[3].Value.ToString();
                    }

                    if (problemName == "")
                    {
                        continue;
                    }

                    string problemAck = "";
                    if (row[5].Value != null)
                    {
                        problemAck = row[5].Value.ToString();
                        if (problemAck == "")
                        {
                            continue;
                        }
                    }
                    if (!StoParams.Instance.htAllProblemTypeAck.ContainsKey(problemName))
                    {
                        StoParams.Instance.htAllProblemTypeAck[problemName] = problemAck;
                    }
                    /*string problemName = "";
                    if (row[3].Value != null)
                    {
                        problemName = row[3].Value.ToString();
                    }

                    if (problemName=="")
                    {
                        continue;
                    }
                  
                    string problemAck = "";
                    if(row[11].Value!=null)
                    {
                        problemAck = row[11].Value.ToString();
                        if (problemAck == "")
                        {
                            continue;
                        }
                    }

                    string customerName = "";
                    if(row[8].Value!=null)
                    {
                        customerName = row[8].Value.ToString();
                    }

                    string groupType = "";
                    if (row[12].Value != null)
                    {
                        groupType = row[12].Value.ToString();
                    }

                    string employee = "";
                    if (row[13].Value != null)
                    {
                        employee = row[13].Value.ToString();
                    }

                    string groupName = "";
                    if (row[14].Value != null)
                    {
                        groupName = row[14].Value.ToString();
                    }

               

                    if(!StoParams.Instance.htAllProblemTypeAck.ContainsKey(problemName))
                    {
                        StoParams.Instance.htAllProblemTypeAck[problemName] = problemAck;
                    }
                    CustomerAndDutyPerson cusPerson = new CustomerAndDutyPerson();
                    cusPerson.customerName = customerName.Trim();

                    cusPerson.groupType = groupType;
                    cusPerson.groupName = groupName;
                    cusPerson.employee = employee;
                    if(!StoParams.Instance.htCustomerAndDuty.ContainsKey(cusPerson.customerName))
                    {
                        StoParams.Instance.htCustomerAndDuty[cusPerson.customerName] = cusPerson;
                    }*/







                }
                LogHelper.Instance.writeLog("初始化完成：类型共有 "+ StoParams.Instance.htAllProblemTypeAck.Count.ToString());


                /*ArrayList arListReg = UtilityHelp.Instance.getTokenSiteName(path);
                if (arListReg.Count > 0)
                {
                    foreach (string strLine in arListReg)
                    {
                        if (strLine.Length > 3)
                        {
                            string newLine = strLine.Replace("：", ":");
                            string[] arr = newLine.Split(':');
                            if (arr.Length == 2)
                            {           
                                StoParams.Instance.htAllProblemTypeAck[arr[0]] = arr[1];
                            }                          





                        }

                    }
                }*/

            }
            catch (Exception ex)
            {
                LogHelper.Instance.writeLog("初始化完成：ex  " + ex.ToString()+" 行号："+ curRow.ToString());
            }

        }
        public void initSiteToken()
        {
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.TokenSitePath;
                ArrayList arListReg = UtilityHelp.Instance.getTokenSiteName(path);
                if (arListReg.Count > 0)
                {                    
                    foreach (string strLine in arListReg)
                    {
                        if (strLine.Length > 3)
                        {
                            string[] arr = strLine.Split('$');
                            RegBean regBean = new RegBean();
                            regBean.token = arr[0];
                            regBean.regSiteName = arr[1];
                            regBean.regSiteID = arr[2];
                            regBean.regSiteCode = arr[3];
                            regBean.regWechate = arr[4];
                            if(arr.Length>5)
                            {
                                regBean.user = arr[5];
                                StoParams.Instance.htTokenUser[regBean.token] = regBean.user;
                            }
                            regBean.isAnthorized = true;
                            if(!StoParams.Instance.regAllSites.Contains(regBean.regSiteName))
                            {
                                StoParams.Instance.regAllSites = StoParams.Instance.regAllSites + regBean.regSiteName + " ";
                            }
                            
                            if (MemberInfo.Instance.token=="")
                            {
                                MemberInfo.Instance.token = arr[0];
                                StoParams.Instance.register_code= arr[3];
                                StoParams.Instance.register_site= arr[1];
                            }

                            StoParams.Instance.htRegSiteNameAndReg[regBean.regSiteName] = regBean.regSiteID;
                            StoParams.Instance.htRegSiteNameAndToken[regBean.regSiteName] = arr[0];
                            if (!StoParams.Instance.htRegInfo.ContainsKey(regBean.regSiteName))
                            {
                                ArrayList arListRegBean = new ArrayList();
                                arListRegBean.Add(regBean);
                                StoParams.Instance.htRegInfo[regBean.regSiteName] = arListRegBean;
                            }
                            else
                            {
                                ArrayList arListRegBean = StoParams.Instance.htRegInfo[regBean.regSiteName] as ArrayList;
                                arListRegBean.Add(regBean);
                                StoParams.Instance.htRegInfo[regBean.regSiteName] = arListRegBean.Clone();
                            }
                            //StoParams.Instance.htRegInfo[regBean.regSiteName] = regBean;


                        }

                    }
                }
            }
            catch (Exception ex)
            {

            }
        }




        public void initCloseRoom()
        {
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.CloseSitePath;
                ArrayList arListReg = UtilityHelp.Instance.getTokenSiteName(path);
                if (arListReg.Count > 0)
                {
                    foreach (string strLine in arListReg)
                    {
                        if (strLine.Length > 3)
                        {
                            FrameDecoderManager.Instance.htRoomClose[strLine.Trim()] = "close";


                        }

                    }
                }
            }
            catch (Exception ex)
            {

            }
        }


        public void initGroupRoom()
        {
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.GroupRoomPath;
                ArrayList arListReg = UtilityHelp.Instance.getTokenSiteName(path);
                if (arListReg.Count > 0)
                {
                    foreach (string strLine in arListReg)
                    {
                        if (strLine.Length > 3)
                        {
                            string strNewLine = strLine.Replace("：", ":");
                            string[] arr = strNewLine.Split(':');
                            if(arr.Length==2)
                            {
                                FrameDecoderManager.Instance.htGroupNameRooms[arr[0]] = arr[1];
                            }
                   


                        }

                    }
                }
            }
            catch (Exception ex)
            {

            }
        }



        public ArrayList getTokenSiteArrList()
        {
            ArrayList arListRes = new ArrayList();
            try
            {
                foreach(DictionaryEntry de in  StoParams.Instance.htRegInfo)
                {
                    ArrayList arListRegs= (ArrayList)de.Value;
                    foreach(RegBean regBean  in arListRegs)
                    {
                        string strLine = regBean.token + "$" + regBean.regSiteName + "$" + regBean.regSiteID + "$" + regBean.regSiteCode + "$" + regBean.regWechate;
                        arListRes.Add(strLine);
                    }
                    //RegBean regBean = (RegBean)de.Value;
                    
                }
            }
            catch(Exception ex)
            {

            }
            return arListRes;
        }



        public void initGroupPos(ArrayList arListGroupPos)
        {
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.PosSitePath;
                ArrayList arListReg = UtilityHelp.Instance.getTokenSiteName(path);
                if (arListReg.Count > 0)
                {
                    foreach (string strLine in arListReg)
                    {
                        if (strLine.Length > 3)
                        {
                            GroupPos gropPos = new GroupPos();
                            JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(strLine);
                            string startX = jsonObjRes["startx"].ToString();
                            string starty = jsonObjRes["starty"].ToString();

                            string inputX = jsonObjRes["inputx"].ToString();
                            string inputY = jsonObjRes["inputy"].ToString();
                            string groupName = jsonObjRes["groupName"].ToString();
                            string replyer = jsonObjRes["replyer"].ToString();
                            string roomid = jsonObjRes["roomid"].ToString();
                            string msgType = jsonObjRes["msgType"].ToString();

                            if (jsonObjRes.Property("doOrderCancel") != null)
                            {
                                bool doOrderCancel = Convert.ToBoolean(jsonObjRes["doOrderCancel"].ToString());
                                gropPos.doOrderCancel = doOrderCancel;

                            }
                            gropPos.groupName = groupName;
                            gropPos.replyUser = replyer;
                            gropPos.readPos = new System.Drawing.Point(Convert.ToInt32(startX), Convert.ToInt32(starty));
                            gropPos.inputPos = new System.Drawing.Point(Convert.ToInt32(inputX), Convert.ToInt32(inputY));
                            gropPos.roomID = roomid;
                            gropPos.msgType = msgType;
                            arListGroupPos.Add(gropPos);
                            //FrameDecoderManager.Instance.htGropRoomID[roomid] = gropPos;
                     


                        }

                    }
                }
            }
            catch (Exception ex)
            {

            }
        }


        public void initGroupPos()
        {
            try
            {
                string path = System.Environment.CurrentDirectory + "\\config\\" + StoParams.Instance.PosSitePath;
                ArrayList arListReg = UtilityHelp.Instance.getTokenSiteName(path);
                if (arListReg.Count > 0)
                {
                    foreach (string strLine in arListReg)
                    {
                        if (strLine.Length > 3)
                        {
                            GroupPos gropPos = new GroupPos();
                            JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(strLine);
                            string startX = jsonObjRes["startx"].ToString();
                            string starty = jsonObjRes["starty"].ToString();

                            string inputX = jsonObjRes["inputx"].ToString();
                            string inputY = jsonObjRes["inputy"].ToString();
                            string groupName= jsonObjRes["groupName"].ToString();
                            string replyer = jsonObjRes["replyer"].ToString();
                            string roomid = jsonObjRes["roomid"].ToString();
                            string msgType = jsonObjRes["msgType"].ToString();

                            if(jsonObjRes.Property("doOrderCancel")!=null)
                            {
                                bool doOrderCancel = Convert.ToBoolean(jsonObjRes["doOrderCancel"].ToString());
                                gropPos.doOrderCancel = doOrderCancel;

                            }
                            gropPos.groupName = groupName;
                            gropPos.replyUser = replyer;
                            gropPos.readPos = new System.Drawing.Point(Convert.ToInt32(startX), Convert.ToInt32(starty));
                            gropPos.inputPos = new System.Drawing.Point(Convert.ToInt32(inputX), Convert.ToInt32(inputY));
                            gropPos.roomID = roomid;
                            gropPos.msgType = msgType;
                            //MessageHandleManager.Instance.arListGroupPos.Add(gropPos);
                            FrameDecoderManager.Instance.htGropRoomID[roomid] = gropPos;
             


                        }

                    }
                }
            }
            catch (Exception ex)
            {

            }
        }


        public string getDateTime(string strLine)
        {
            string res = "";
            try
            {
                strLine = strLine.Replace("_", "-");
                if (strLine.Contains("%&"))
                {
                    strLine = strLine.Substring(strLine.IndexOf("%&") + 2);
                }
                if(strLine.Contains("2022-"))
                {
                    strLine = strLine.Insert(strLine.IndexOf("2022-"), " ");
                }
                if (strLine.Contains("2023-"))
                {
                    strLine = strLine.Insert(strLine.IndexOf("2023-"), " ");
                }
                if (strLine.Contains("2024-"))
                {
                    strLine = strLine.Insert(strLine.IndexOf("2024-"), " ");
                }
                if (strLine.Contains("2025-"))
                {
                    strLine = strLine.Insert(strLine.IndexOf("2025-"), " ");
                }
                strLine = strLine.Replace("  ", " ");
                strLine = strLine.Replace("至", " ");
                var regex = new Regex(@"\b\d{4}-\d{2}-\d{2}\b");
                bool findDate = false;
                /*foreach (Match m in regex.Matches(strLine))
                {
                    DateTime dt;
                    if (DateTime.TryParseExact(m.Value, "yyyy-MM-dd", null, DateTimeStyles.None, out dt))
                    {
                        findDate = true;
                        res = res + " " + m.Value;
                    }                      
                }*/
                if(!findDate)
                {
                    regex = new Regex(@"\b\d{4}-\d{1,2}-\d{1,2}\b");
                  
                    foreach (Match m in regex.Matches(strLine))
                    {
                        DateTime dt;
                        string[] arrTimeFormat = new string[4];
                        arrTimeFormat[0] = "yyyy-MM-dd";
                        arrTimeFormat[1] = "yyyy-M-dd";
                        arrTimeFormat[2] = "yyyy-MM-d";
                        arrTimeFormat[3] = "yyyy-M-d";
                        if (DateTime.TryParseExact(m.Value, arrTimeFormat, null, DateTimeStyles.None, out dt))
                        {
                            findDate = true;
                            res = res + " " + m.Value;
                        }
                    }
                }
                if(res.Length>4)
                {
                    return res;
                }
                regex = new Regex(@"\b\d{4}-\d{2}-\d{1}\b"); ;
                foreach (Match m in regex.Matches(strLine))
                {
                    DateTime dt;                    
                    res = Convert.ToDateTime(m.Value).ToString("yyyy-MM-dd");
                    return res;
                }


            }
            catch(Exception ex)
            {

            }
            return res;
        }

        public string getNoRoadMapList(string strLine)
        {
            string res = "";
            try
            {
                string timeDuring=UtilityHelp.Instance.getDateTime(strLine);
                if(timeDuring=="")
                {
                    logHelp.LogHelper.Instance.writeLog("没提取到有效日期");
                    return res;
                }

                string dir = System.Environment.CurrentDirectory + "\\log";
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                //判断文件是否存在，不存在则创建的存在
                string sPath = dir;
                string date = Convert.ToDateTime(timeDuring).ToString("yyyy-MM-dd");
                sPath = Path.Combine(dir, date + "-noroadmap.txt");
                //System.Windows.Forms.MessageBox.Show("sPath:" + sPath);
                if (!File.Exists(sPath))
                {
                    if(System.DateTime.Now.Hour>9)
                    {
                        logHelp.LogHelper.Instance.writeLog(sPath + "文件不存在");
                    }
                    
                    return res;
                }

                ArrayList arListNoroadMapBarcode = UtilityHelp.Instance.getArrayLine(sPath, date);
                if (arListNoroadMapBarcode.Count > 0)
                {
                    foreach (string strBarcode in arListNoroadMapBarcode)
                    {
                        if (strBarcode.Length > 3)
                        {
                            res = res + strBarcode + "\r\n";
                        }

                    }
                    res = res.TrimEnd(new char[] { '\r', '\n' });
                }
            }
            catch (Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog("发生异常："+ex.ToString());
            }
            return res;
        }


        public bool isLanshouParcel(string ori_addr)
        {
            bool res = false;
            try
            {
                if ((ori_addr.Contains("揽收") ||
                    ori_addr.Contains("揽件") )
                    && (!isInterCept(ori_addr)) && (!isChangeAddr(ori_addr, "123")&&!isCuiParcel(ori_addr))&&!ori_addr.Contains("重量"))
                {
                  
                    res = true;
                }

            }
            catch (Exception ex)
            {

            }
            return res;
        }


        /// <summary>
        /// 是否是刷留言指定派件员
        /// </summary>
        /// <param name="ori_addr"></param>
        /// <returns></returns>
        public bool isAssignPJYParcel(string ori_addr)
        {
            bool res = false;
            try
            {
                if (ori_addr.Contains("留言板")&& ori_addr.Length<7)
                {

                    res = true;
                }

            }
            catch (Exception ex)
            {

            }
            return res;
        }

        /// <summary>
        /// 是否是获取用户丝逆袭
        /// </summary>
        /// <param name="ori_addr"></param>
        /// <returns></returns>
        public bool isGetUserPhone(string ori_addr)
        {
            bool res = false;
            try
            {
                if (ori_addr.Contains("电联") && ori_addr.Trim().Length < 6)
                {

                    res = true;
                }

            }
            catch (Exception ex)
            {

            }
            return res;
        }

        /// <summary>
        /// 规范拦截未退回
        /// </summary>
        /// <param name="ori_addr"></param>
        /// <returns></returns>
        public bool isGuifanInterNotReturn(string ori_addr)
        {
            bool res = false;
            try
            {
                if (ori_addr.Replace(" ","").Contains("拦截未退回"))
                {
                    res = true;
                }

            }
            catch (Exception ex)
            {

            }
            return res;
        }



        /// <summary>
        /// 延误查件
        /// </summary>
        /// <param name="ori_addr"></param>
        /// <returns></returns>
        public bool isDelayCheckParcel(string ori_addr)
        {
            bool res = false;
            try
            {
                //if(StoParams.Instance.register_site.Contains("东升")|| StoParams.Instance.register_site.Contains("和顺") || StoParams.Instance.register_site.Contains("百安"))
                {
                    if (ori_addr.Replace(" ", "").Contains("延误查件")|| ori_addr.Replace(" ", "").Contains("延误仲裁查件"))
                    {
                        res = true;
                    }
                }                

            }
            catch (Exception ex)
            {

            }
            return res;
        }



        public bool isChangeNumber(string addr)
        {
            bool res = false;
            try
            {
                
                if (addr.Contains("改号码") || addr.Contains("改电话") || addr.Contains("改手机")
                    || addr.Contains("改手机号码") || addr.Contains("改下电话") || addr.Contains("改下号码")
                    || addr.Contains("新号码") || addr.Contains("新电话") || addr.Contains("改手机"))
                {
                    res = true;

                }

            }
            catch (Exception ex)
            {

            }
            return res;
        }


        public bool isContainQuestion(string addr)
        {
            bool res = false;
            try
            {
                if(!StoParams.Instance.isStrictMode)
                {
                    return res;
                }
                if(addr.Contains("吗") || addr.Contains("怎么") || addr.Contains("为什么") || addr.Contains("核实") || addr.Contains("原因"))
                {
                    if(!addr.Contains("催件"))
                    {
                        res = true;
                    }
                   
                }

            }
            catch(Exception ex)
            {

            }
            return res;
        }

        public bool isCuiParcel(string ori_addr)
        {
            bool res = false;
            try
            {
                if ((ori_addr.Contains("催件") || 
                    ori_addr.Contains("签收未收到") ||                    
                    ori_addr.Contains("未收到") ||
                     ori_addr.Contains("送货上门") ||
                    ori_addr.Contains("催物流") ||
                    ori_addr.Contains("长时间不更新"))
                    &&(!isInterCept(ori_addr))&&(!isChangeAddr(ori_addr,"123")))
                {
                    res = true;
                }
                else if (ori_addr.Length == 1 && ori_addr.EndsWith("催") )
                {
                    res = true;
                }
                else if (ori_addr.Trim().Length == 2 && (ori_addr.Trim().Contains("遗失")|| ori_addr.Trim().Contains("破损") || ori_addr.Trim().Contains("短少")))
                {
                    res = true;
                }
                else if (ori_addr.Length<4 && ori_addr.StartsWith("催")&&!ori_addr.Contains("拦截") && !ori_addr.Contains("退"))
                {
                    res = true;
                }


            }
            catch (Exception ex)
            {

            }
            return res;
        }


        public bool isCheckWeight(string ori_addr)
        {
            bool res = false;
            try
            {
                if (ori_addr.Replace(" ", "").Contains("查重") || (ori_addr.Replace(" ", "").Contains("核重") && ori_addr.Length < 10) || (ori_addr.Replace(" ", "").Contains("称重")&& ori_addr.Length<10) || ori_addr.Replace(" ", "").Contains("查看重量")
                        || ori_addr.Replace(" ", "").Contains("核重") || ori_addr.Replace(" ", "").Contains("查克重") || ori_addr.Replace(" ", "").Contains("计重") || ori_addr.Replace(" ", "").Contains("多重")
                    || ori_addr.Replace(" ", "").Replace("。", "").EndsWith("重量") || (ori_addr.Replace(" ", "").Replace("。", "").Contains("重量") && ori_addr.Replace(" ", "").Length < 8))
                {
                    res = true;
                }

            }
            catch (Exception ex)
            {

            }
            return res;
        }


        public bool isCancelChangeAddr(string ori_addr)
        {
            bool res = false;
            try
            {
                if ((ori_addr.Replace(" ", "").Contains("撤销改地址") 
                    || (ori_addr.Replace(" ", "").Contains("取消改地址"))
                    || (ori_addr.Replace(" ", "").Contains("取消修改地址"))
                     || (ori_addr.Replace(" ", "").Contains("取消改址"))
                      || (ori_addr.Replace(" ", "").Contains("撤销改址"))
                    || (ori_addr.Replace(" ", "").Contains("撤销修改地址"))
                    )
                    && ori_addr.Length<30)
                {
                    res = true;
                }

            }
            catch (Exception ex)
            {

            }
            return res;
        }


        public bool isTransfer(string ori_addr)
        {
            bool res = false;
            try
            {
                if(ori_addr.Contains("JT"))
                {
                    ori_addr = ori_addr.Substring(ori_addr.LastIndexOf("JT"));
                    ori_addr = ori_addr.Substring(13);
                }
                if ((ori_addr.Contains("中转") && ori_addr.Trim().Length==2)|| ori_addr.EndsWith("中转"))
                {
                    res = true;
                }
                if ((ori_addr.Trim().Contains("转") && ori_addr.Trim().Length == 1) || ori_addr.EndsWith("中转"))
                {
                    res = true;
                }

                

            }
            catch (Exception ex)
            {

            }
            return res;
        }



        public bool isLanshouaddr(string ori_addr)
        {
            bool res = false;
            try
            {
                ori_addr = ori_addr.Replace("揽件", "揽收");
                if (ori_addr.Contains("JT"))
                {
                    ori_addr = ori_addr.Substring(ori_addr.LastIndexOf("JT"));
                    ori_addr = ori_addr.Substring(13);
                }
                if ((ori_addr.Contains("揽收") && ori_addr.Trim().Length == 2) || ori_addr.EndsWith("揽收"))
                {
                    res = true;
                }
                if ((ori_addr.Trim().Contains("收") && ori_addr.Trim().Length == 1) || ori_addr.EndsWith("中转"))
                {
                    res = true;
                }
                
                if (ori_addr.Contains("揽收"))
                {
                    int lanshouIndex = ori_addr.IndexOf("揽收");
                    if(ori_addr.Length- lanshouIndex<7)
                    {
                        res = true;
                    }
                }



            }
            catch (Exception ex)
            {

            }
            return res;
        }



        public bool isCancelInter(string ori_addr)
        {
            bool res = false;
            try
            {
                if (ori_addr.Contains("撤销拦截") || ori_addr.Contains("取消拦截") || ori_addr.Contains("取消退回")
                    || ori_addr.Contains("退回取消") || ori_addr.Contains("撤销退回")
                     || ori_addr.Contains("不要退回") || ori_addr.Contains("不用退回")
                       || ori_addr.Contains("取消退回") || ori_addr.Contains("继续派件")
                        || ori_addr.Contains("继续派送") || ori_addr.Contains("取消截回")
                    || ori_addr.Contains("拦截撤销") || ori_addr.Contains("退回撤销"))
                {
                    res = true;                    
                }

            }
            catch (Exception ex)
            {

            }
            return res;
        }

        public bool isCancelOrder(string ori_addr)
        {
            bool res = false;
            try
            {
                if (ori_addr.Contains("订单取消")|| ori_addr.EndsWith("取消单"))
                {
                    res = true;
                }

            }
            catch (Exception ex)
            {

            }
            return res;
        }



        public bool isInterCept(string ori_addr)
        {
            bool res = false;
            try
            {
                if(isCancelInter(ori_addr)||isChangeAddr(ori_addr,""))
                {
                    return res;
                }
                if (ori_addr.Contains("不要了") || ori_addr.Contains("已退款") || (ori_addr.Contains("催退") && !ori_addr.Contains("催退款"))
                   || ori_addr.Contains("已退款成功") || ori_addr.Contains("客户拒收") || ori_addr.Contains("加急退回"))
                {
                    res = true;
                    return res;
                }
        

                if (ori_addr.Contains("拦截") || ori_addr.Contains("撤件")
                    || ori_addr.Contains("退回") || ori_addr.Contains("截回")
                    || ori_addr.Contains("追回") || ori_addr.Contains("召回") || ori_addr.Contains("拦回")
                    || ori_addr.Contains("已退款") || ori_addr.Contains("已经退款")
                    || ori_addr.Contains("撤回"))
                {
                    res = true;
                    if ((ori_addr.Contains("有没有换单退回")
                        || (ori_addr.Contains("是否换单退回"))
                         || (ori_addr.Contains("有无换单退回"))
                         || (ori_addr.Contains("是否有换单退回"))
                          || (ori_addr.Contains("是否是换单退回"))
                          || (ori_addr.Contains("被退回"))
                        || (ori_addr.Contains("是否已换单退回")))
                        && ori_addr.Contains("核实"))
                    {
                        res = false;
                    }
                    if ((ori_addr.Contains("不要退回")
                        || (ori_addr.Contains("不要拦截"))
                         || (ori_addr.Contains("取消退回"))
                         || (ori_addr.Contains("取消拦截"))
                          || (ori_addr.Contains("是否是换单退回"))
                        || (ori_addr.Contains("是否已换单退回")))
                        && ori_addr.Contains("催"))
                    {
                        res = false;
                    }

                    if ((ori_addr.Contains("不要退回")
                        || (ori_addr.Contains("不要拦截"))
                         || (ori_addr.Contains("没有要求退回"))
                          || (ori_addr.Contains("没有要求拦截"))
                           || (ori_addr.Contains("没有要求撤回"))
                           || (ori_addr.Contains("没要求退回"))
                          || (ori_addr.Contains("没要求拦截"))
                           || (ori_addr.Contains("没要求撤回"))
                           || (ori_addr.Contains("没要退回"))
                          || (ori_addr.Contains("没要拦截"))
                           || (ori_addr.Contains("没要撤回"))
                        || (ori_addr.Contains("不要召回"))
                        || (ori_addr.Contains("没有拒收"))
                        || (ori_addr.Contains("不要撤回"))
                         || (ori_addr.Contains("取消退回"))
                         || (ori_addr.Contains("取消拦截"))
                          || (ori_addr.Contains("是否是换单退回"))
                        || (ori_addr.Contains("怎么又退回"))
                        || (ori_addr.Contains("怎么退回来了")))
                       )
                    {
                        res = false;
                    }
                }
                else if (ori_addr.Length == 1 && (ori_addr.EndsWith("退") || ori_addr.EndsWith("拦") || ori_addr.EndsWith("截") || ori_addr.EndsWith("召")))
                {
                    res = true;
                }

            }
            catch (Exception ex)
            {

            }
            return res;
        }



        public bool isChangePhone(string addr)
        {
            bool res = false;
            try
            {
                if(addr.Contains("电话修改为")|| addr.Contains("电话改为") || addr.Contains("改电话"))
                {
                    res = true;
                }

            }
            catch(Exception ex)
            {

            }
            return res;
        }

        public bool isChangeAddr(string addr,string barcode)
        {
            bool res = false;
            try
            {
                if(addr.Replace(" ", "").Contains("改地址")&& addr.Length>13&& 
                    !addr.Contains("不要改地址") && !addr.Contains("不改地址")&&!addr.Contains("未有要改地址")
                    && !addr.Contains("未要改地址"))
                {
                    res = true;
                }
                List<string> phoneList = GetTelephoneList(addr, barcode);
                if (addr.Contains("地址改为") || addr.Contains("地址修改为") || addr.Contains("地址更改为") || addr.Contains("地址改变为") || addr.Contains("地址更新为") || addr.Contains("地址更新成"))
                {
                    res = true;
                }
                else if (addr.Contains("改成") && phoneList.Count > 0 && !addr.Contains("电话改成"))
                {
                    res = true;
                    if (addr.Length < 30 && !addr.Contains("地址"))
                    {
                        res = false;
                    }
                }
                else if (addr.Contains("改为") && phoneList.Count > 0 && !addr.Contains("电话改为"))
                {
                    res = true;
                    if (addr.Length < 25&& !addr.Contains("地址"))
                    {
                        res = false;
                    }
                }
                else if (addr.Contains("更改为") && phoneList.Count > 0 && !addr.Contains("电话更改为"))
                {
                    res = true;
                    if (addr.Length < 25 && !addr.Contains("地址"))
                    {
                        res = false;
                    }
                }
                else if (addr.Contains("换地址") && phoneList.Count > 0 && !addr.Contains("电话更改为"))
                {
                    res = true;
                }


                if (addr.Contains("改")&& addr.Contains("地址")&& phoneList.Count>0)
                {
                    int addrIndex = addr.LastIndexOf("地址");
                    int changeIndex = addr.LastIndexOf("改");
                    if(addrIndex> changeIndex&& addrIndex- changeIndex<=7)
                    {
                        res = true;
                    }
                   
                }
                

            }
            catch(Exception ex)
            {

            }
            return res;
        }


        public ArrayList getDifferentTasks(ArrayList arListAllTask)
        {
            ArrayList arListResTypeTaskList = new ArrayList();
            Hashtable htTaskTypeList = new Hashtable();
            try
            {
                ArrayList arListTaskTypes = new ArrayList();
                foreach (ParcelBean parcelBean in arListAllTask)
                {
                    if(!htTaskTypeList.ContainsKey(parcelBean.taskType)&& parcelBean.taskType.Length>1)
                    {
                        htTaskTypeList[parcelBean.taskType] = new ArrayList();
                        arListTaskTypes.Add(parcelBean.taskType);
                    }
                    ArrayList arListCurTypeTasks = htTaskTypeList[parcelBean.taskType] as ArrayList;
                    arListCurTypeTasks.Add(parcelBean);
                    
                }                    
                foreach (string taskType in arListTaskTypes)
                {
                    if(htTaskTypeList.ContainsKey(taskType))
                    {
                        ArrayList arListCurTypeTaskList = htTaskTypeList[taskType] as ArrayList;
                        arListResTypeTaskList.Add(arListCurTypeTaskList);
                    }
                   
                }
            }
            catch (Exception ex)
            {

            }
            return arListResTypeTaskList;

        }


        public ArrayList getDifferentSenderTask(ArrayList arListAllTask)
        {
            ArrayList arListResSenderTaskList = new ArrayList();
            try
            {
                ArrayList arListSenderName = new ArrayList();
                foreach(ParcelBean parcelBean in arListAllTask)
                {
                    if(parcelBean.senderWeChat=="")
                    {
                        parcelBean.senderWeChat = parcelBean.fromWxID;
                    }
                    if(!arListSenderName.Contains(parcelBean.senderWeChat))
                    {
                        arListSenderName.Add(parcelBean.senderWeChat);
                    }
                }
                foreach(string senderWechat in arListSenderName)
                {
                    ArrayList arListCurTasks = new ArrayList();
                    foreach(ParcelBean parcelBean in arListAllTask)
                    {
                        if(parcelBean.senderWeChat== senderWechat)
                        {
                            arListCurTasks.Add(parcelBean);
                        }
                        if(arListCurTasks.Count>52&& (!parcelBean.taskType.Contains("统计"))&&!parcelBean.taskType.Contains("退转问题件"))
                        {
                            arListResSenderTaskList.Add(arListCurTasks.Clone());
                            arListCurTasks.Clear();
                            arListCurTasks = new ArrayList();
                        }
                    }
                    if(arListCurTasks.Count>0)
                    {
                        arListResSenderTaskList.Add(arListCurTasks);
                    }
                    
                }
            }
            catch(Exception ex)
            {

            }
            return arListResSenderTaskList;

        }


        public bool isBingoMainTxt(string content, string startTxt,string endTxt,int betweenChars)
        {
            try
            {
                if(content.Contains(startTxt)&& content.Contains(endTxt))
                {
                    int startIndex = content.IndexOf(startTxt);
                    int endIndex = content.IndexOf(endTxt);
                    if(endIndex> startIndex&& (endIndex- startIndex)< betweenChars)
                    {
                        return true;
                    }

                }
            }
            catch(Exception ex)
            {

            }
            return false;
        }



        public ArrayList getStaticList(string queryDate,string roomid="")
        {
            ArrayList arListRes = new ArrayList();
            ArrayList arListTotal = new ArrayList();
            try
            {               
                string dir = System.Environment.CurrentDirectory + "\\log";
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                //判断文件是否存在，不存在则创建的存在
                string sPath = dir;
                string date = queryDate.Trim();

                string[] files = date.Split(' ');
                
                arListTotal.Clear();
                int spanDays = 0;
                if(files.Length==2)
                {
                    TimeSpan ts = Convert.ToDateTime(files[1]) - Convert.ToDateTime(files[0]);
                    spanDays = (int)ts.TotalDays;
                }
                DateTime dtStart = Convert.ToDateTime(files[0]);
                DateTime dtEnd = dtStart;
                if(files.Length==2)
                {
                    dtEnd=Convert.ToDateTime(files[1]);
                }

                while (dtStart<= dtEnd)
                {
                    string dateQuery = dtStart.ToString("yyyy-MM-dd");
                    sPath = Path.Combine(dir, dateQuery + "-static.txt");
                    //System.Windows.Forms.MessageBox.Show("sPath:" + sPath);
                    if (!File.Exists(sPath))
                    {
                        dtStart = dtStart.AddDays(1);
                        logHelp.LogHelper.Instance.writeLog(sPath + "文件不存在");
                        continue;
                    }
                    arListRes = UtilityHelp.Instance.getArrayLine(sPath, dateQuery);
                    arListTotal.AddRange(arListRes);
                    dtStart = dtStart.AddDays(1);
                }
               
                Hashtable htNoRoadMap = new Hashtable();
                ArrayList arListTodel = new ArrayList();
                Hashtable htInterCeptAssigned = new Hashtable();
                foreach(string strLine in arListTotal)
                {
                    if(!strLine.Contains("$"))
                    {
                        continue;
                    }
                    if(!StoParams.Instance.isStrictMode)
                    {
                        if (roomid != "" && !strLine.Contains(roomid))
                        {
                            arListTodel.Add(strLine);
                            continue;
                        }
                    }
                    
                    string[] arr = strLine.Split('$');
                    if (arr[0].Contains("拦截无物流")|| arr[0].Contains("拦截失败"))
                    {                        
                        string barcode = arr[1];
                        htNoRoadMap[barcode] = strLine;
                    }
                    else if(arr[0]=="拦截"|| arr[0] == "取消拦截")
                    {
                        if(htNoRoadMap.ContainsKey(arr[1]))
                        {
                            arListTodel.Add(htNoRoadMap[arr[1]] as string);
                        }
                    }
                    if (arr[0].Contains("拦截件已签收"))
                    {
                        if(!htInterCeptAssigned.ContainsKey(arr[1]))
                        {
                            htInterCeptAssigned[arr[1]] = arr[1];
                        }
                        else
                        {
                            continue;
                        }

                    }


                    if (arr[0].Contains("改地址无物流"))
                    {
                        string barcode = arr[1];
                        htNoRoadMap[barcode] = strLine;
                    }
                    else if (arr[0].Contains("改地址未出"))
                    {
                        string barcode = arr[1];
                        htNoRoadMap[barcode] = strLine;
                    }
                    else if (arr[0] == "改地址")
                    {
                        if (htNoRoadMap.ContainsKey(arr[1]))
                        {
                            arListTodel.Add(htNoRoadMap[arr[1]] as string);
                        }
                    }
                }

                foreach(string strLine in arListTodel)
                {
                    if(arListTotal.Contains(strLine))
                    {
                        arListTotal.Remove(strLine);
                    }
                }

                /*if (!File.Exists(sPath))
                {
                    logHelp.LogHelper.Instance.writeLog(sPath + "文件不存在");
                    return arListRes;
                }*/
               
            }
            catch (Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog("发生异常：" + ex.ToString());
            }
            return arListTotal;
        }




        public bool genStaticExcelForMsgBoard(out string outputPath, ArrayList arListMsgBeans, string roomid = "")
        {
            outputPath = "";
            string queryDate = "";
            bool res = false;
            try
            {
                logHelp.LogHelper.Instance.writeLog("开始生成msgboard excel文件。");
          
                queryDate = System.DateTime.Now.ToString("yyyyMMddHHmm");



                string logDir = System.Environment.CurrentDirectory + "\\log";
                if (!Directory.Exists(logDir))
                {
                    Directory.CreateDirectory(logDir);
                }
                //判断文件是否存在，不存在则创建的存在
                string sPath = logDir;
                sPath = Path.Combine(logDir, queryDate + "-static.xlsx");
                outputPath = sPath;
                
                string dir = System.Environment.CurrentDirectory + "\\static";
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                //判断文件是否存在，不存在则创建的存在
                sPath = dir;

                sPath = Path.Combine(dir, queryDate + "-static.xlsx");
                outputPath = sPath;

                res = UtilityExcel.Instance.GenExcelForStatic(arListMsgBeans, sPath);

                outputPath = uploadToAliyun(sPath, "");

            }
            catch (Exception ex)
            {

            }
            return res;
        }




        public bool genStaticExcel(out string outputPath,string groupName,string strLine,string roomid="")
        {
            outputPath = "";
            string queryDate = "";
            bool res = false;
            try
            {
                logHelp.LogHelper.Instance.writeLog("开始生成excel文件。");
                string timeDuring = UtilityHelp.Instance.getDateTime(strLine);
                if (timeDuring == "")
                {
                    queryDate = System.DateTime.Now.ToString("yyyy-MM-dd");
                }
                else
                {
                    queryDate = timeDuring;
                }
                queryDate = queryDate.Trim();



                string logDir = System.Environment.CurrentDirectory + "\\log";
                if (!Directory.Exists(logDir))
                {
                    Directory.CreateDirectory(logDir);
                }
                //判断文件是否存在，不存在则创建的存在
                string sPath = logDir;
                sPath = Path.Combine(logDir, queryDate + "-static.xlsx");
                outputPath = sPath;
                ArrayList arListStatics = getStaticList(queryDate, roomid);
                if(arListStatics.Count<1)
                {
                    logHelp.LogHelper.Instance.writeLog("任务 count==0");
                    return res;
                }

                string dir = System.Environment.CurrentDirectory + "\\static";
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                //判断文件是否存在，不存在则创建的存在
                sPath = dir;
   
                sPath = Path.Combine(dir, queryDate + "-static.xlsx");
                outputPath = sPath;
                
                if (!StoParams.Instance.isSimpleStatic)
                {
                    string[] headers = { "改地址未出集散或转运", "揽收时间", "查件人", "催件未出集散或转运", "揽收时间", "查件人", "规范拦截未退回", "揽收时间", "查件人", "改地址无物流", "揽收时间", "查件人", "拦截无物流", "揽收时间", "查件人", "拦截无物流超3天", "揽收时间", "查件人", "签收未收到", "揽收时间", "查件人", "拦截", "揽收时间", "查件人", "拦截件已入库", "揽收时间", "查件人", "改地址", "揽收时间", "查件人", "破损", "揽收时间", "查件人", "催件", "揽收时间", "查件人", "改电话", "揽收时间", "查件人", "取消拦截", "揽收时间", "查件人", "订单取消", "揽收时间", "查件人" };
                    res = UtilityExcel.Instance.GenExcelForStatic(arListStatics, headers, sPath);
                }
                else
                {
                    logHelp.LogHelper.Instance.writeLog("arListStatics count：" + arListStatics.Count.ToString());
                    res = UtilityExcel.Instance.GenExcelForStatic(arListStatics, sPath);
                }
               
                outputPath = uploadToAliyun(sPath, groupName);

            }
            catch(Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog("genStaticExcel ex：" + ex.ToString());
            }
            return res;
        }

        public string uploadToAliyun(string path,string groupName)
        {
            string res = "";
            try
            {
                string base64 = DocumentToBase64Str(path);//改字段为文件或者图片的Base64字符串
                byte[] file = Convert.FromBase64String(base64);
                res = UploadImg(path, file, groupName);

            }
            catch(Exception ex)
            {

            }
            return res;
        }

        public  string UploadImg(string path, byte[] file,string groupName)
        {
            string fileName = path.Substring(path.LastIndexOf('\\') + 1);

            #region 获取Oss配置的内容
            string AccessKeyId = ConfigurationManager.AppSettings["AccessKeyId"];
            string EndPoint = ConfigurationManager.AppSettings["EndPoint"];
            string AccessKeySecret = ConfigurationManager.AppSettings["AccessKeySecret"];
            string BucketName = ConfigurationManager.AppSettings["BucketName"];
            string domain = ConfigurationManager.AppSettings["OSSStorageDomainUrl"];
            #endregion
            MemoryStream requestContent = new MemoryStream(file);

            OssClient _client = new OssClient(EndPoint, AccessKeyId, AccessKeySecret);

            string bukNamepath = groupName + "/"+ fileName;
            _client.PutObject(BucketName, bukNamepath, requestContent);

            var req = new GeneratePresignedUriRequest(BucketName, bukNamepath, SignHttpMethod.Get)
            {
                Expiration = DateTime.Now.AddDays(1)
            };
            string uri = _client.GeneratePresignedUri(req).ToString();
            return uri;
        }

        public  string DocumentToBase64Str(string fileName)
        {
            FileStream filestream = new FileStream(fileName, FileMode.Open);

            byte[] bt = new byte[filestream.Length];
            //调用read读取方法
            filestream.Read(bt, 0, bt.Length);
            string base64Str = Convert.ToBase64String(bt);
            filestream.Close();
            return base64Str;
        }

        public string getClearMsg(string content)
        {
            string res = content;
            try
            {
                if(res.Contains("商品总价")&& res.Contains("物流动态"))
                {
                    res = res.Substring(0, res.IndexOf("商品总价"));
                    string subS = content.Substring(res.IndexOf("商品总价"));
                    if(subS.Contains("拦截")|| subS.Contains("退回"))
                    {
                        res = res + "拦截";
                    }
                    else if (subS.Contains("催件") || subS.Contains("签收未收到") || subS.Contains("催促"))
                    {
                        res = res + "催件";
                    }
                }
                else if (res.Contains("全部") && res.Contains("已完成"))
                {
                    res = res.Substring(0, res.IndexOf("全部"));
                    string subS = content.Substring(res.IndexOf("全部"));
                    if (subS.Contains("拦截") || subS.Contains("退回"))
                    {
                        res = res + "拦截";
                    }
                    else if (subS.Contains("催件") || subS.Contains("签收未收到") || subS.Contains("催促"))
                    {
                        res = res + "催件";
                    }
                }
                else if (res.Contains("售后编码") && res.Contains("退款金额"))
                {
                    res = res.Substring(0, res.IndexOf("售后编码"));
                    string subS = content.Substring(res.IndexOf("售后编码"));
                    if (subS.Contains("拦截") || subS.Contains("退回"))
                    {
                        res = res + "拦截";
                    }
                    else if (subS.Contains("催件") || subS.Contains("签收未收到") || subS.Contains("催促"))
                    {
                        res = res + "催件";
                    }
                }
            }
            catch(Exception ex)
            {

            }
            return res;

        }

        public bool isDoneTask(string taskType,string wayBill,ArrayList arListDone)
        {
            bool isDoneTask = false;
            try
            {
                if(taskType.Contains("留言板"))
                {
                    return isDoneTask;
                }
                foreach(ArrayList arListTaskBeans in arListDone)
                {
                    foreach(ParcelBean parCelBean in arListTaskBeans)
                    {
                        if(parCelBean.wayBill== wayBill&& parCelBean.taskType== taskType&& !parCelBean.taskType.Contains("自动"))
                        {
                            isDoneTask = true;
                        }
                    }
                }
            }
            catch(Exception ex)
            {

            }
            return isDoneTask;

        }



        public bool removeFailTask(string taskType, string wayBill, ArrayList arListDone)
        {
            bool isDoneTask = false;
            try
            {
                ArrayList arListToDel = new ArrayList();
                foreach (ArrayList arListTaskBeans in arListDone)
                {
                    foreach (ParcelBean parCelBean in arListTaskBeans)
                    {
                        if (parCelBean.wayBill == wayBill && parCelBean.taskType == taskType)
                        {
                            isDoneTask = true;
                            arListToDel.Add(parCelBean);
                            break;
                        }
                    }
                }

                foreach(ParcelBean parcel in arListToDel)
                {
                    foreach (ArrayList arListTaskBeans in arListDone)
                    {
                        if(arListTaskBeans.Contains(parcel))
                        {
                            arListTaskBeans.Remove(parcel);
                        }
                    }
                }
            }
            catch (Exception ex)
            {

            }
            return isDoneTask;

        }



        public void setTokenInvalid(string token)
        {
            try
            {
                foreach (DictionaryEntry de in StoParams.Instance.htRegInfo)
                {
                    string siteName = de.Key.ToString();
                    ArrayList arListRegBeans = (ArrayList)de.Value;
                    foreach (RegBean regBean in arListRegBeans)
                    {
                        if(regBean.token== token)
                        {
                            regBean.isLimitInterFace = true;
                            regBean.dtLimitTime = System.DateTime.Now;
                        }                        
                    }
                    //RegBean regBean = (RegBean)de.Value;


                }

            }
            catch(Exception ex)
            {

            }
        }

        public void setTokenValid(string token)
        {
            try
            {
                foreach (DictionaryEntry de in StoParams.Instance.htRegInfo)
                {
                    string siteName = de.Key.ToString();
                    ArrayList arListRegBeans = (ArrayList)de.Value;
                    foreach (RegBean regBean in arListRegBeans)
                    {
                        if (regBean.token == token)
                        {
                            regBean.isLimitInterFace = false;
                        }
                    }
                    //RegBean regBean = (RegBean)de.Value;


                }

            }
            catch (Exception ex)
            {

            }
        }


        public int getHour(string time)
        {
            int res = -1;
            try
            {
                if(time.Contains(":")&& !time.Contains("-"))
                {
                    string sub= time.Substring(0, time.IndexOf(':'));
                    res = Convert.ToInt32(sub);
                }
                else if(time.Contains("-")&& time.Contains(":"))
                {
                    DateTime dt = Convert.ToDateTime(time);
                    res = dt.Hour;
                }
            }
            catch(Exception ex)
            {

            }
            return res;
        }


        public ArrayList getLanshouArList(ArrayList arListBarcodes,string weight="0.3")
        {
            ArrayList arListLanshou = new ArrayList();
            try
            {
                ArrayList arListTemp = new ArrayList();
                foreach(string strLine in arListBarcodes)
                {
                    ParcelBean parcelBean = new ParcelBean();
                    string[] arr = strLine.Split(' ');
                    if(FrameDecoderManager.Instance.arListLanshouFilters.Contains(parcelBean.wayBill))
                    {
                        continue;
                    }
                    if(arr.Length==1)
                    {
                        parcelBean.wayBill = arr[0];
                        parcelBean.weight = weight;
                    }
                    else if(arr.Length == 2)
                    {
                        parcelBean.wayBill = arr[0];
                        if(MathUtility.isRightDigital(arr[1]))
                        {
                            parcelBean.weight = arr[1];
                        }
                        else
                        {
                            parcelBean.weight = weight;
                        }
                        
                    }
                    parcelBean.taskType = "揽收";
                    arListTemp.Add(parcelBean);
                    if(arListTemp.Count>=50)
                    {
                        arListLanshou.Add(arListTemp.Clone());
                        arListTemp.Clear();
                    }
                }
                if(arListTemp.Count>0)
                {
                    arListLanshou.Add(arListTemp.Clone());
                    arListTemp.Clear();
                }
            }
            catch(Exception ex)
            {

            }
            return arListLanshou;
        }


        public bool isUserLine(string strLine,  ArrayList arListUser)
        {
            bool isUserLine = false;
            try
            {
                string[] arrLine = strLine.Split(' ');
                if(arrLine.Length!=2)
                {
                    return isUserLine;
                }
                if (arrLine.Length == 2 && strLine.Contains(":"))
                {
                    if (arListUser.Contains(arrLine[0]) && arrLine[0].Length >= 1)
                    {
                        DateTime dt = Convert.ToDateTime(arrLine[1]);
                        isUserLine = true;
                    }
                }
            }
            catch (Exception ex)
            {

            }
            return isUserLine;

        }


        public bool isReplyUserLine(string strLine, string replyUser)
        {
            bool isReplyUserLine = false;
            try
            {
                string[] arrLine = strLine.Split(' ');
                if (arrLine.Length != 2)
                {
                    return isReplyUserLine;
                }
                if (arrLine.Length == 2 && strLine.Contains(":"))
                {
                    if (replyUser== arrLine[0] && arrLine[0].Length >= 1)
                    {
                        DateTime dt = Convert.ToDateTime(arrLine[1]);
                        isReplyUserLine = true;
                    }
                }
            }
            catch (Exception ex)
            {

            }
            return isReplyUserLine;

        }


        public void handleCompanyContent(Hashtable htRes,ArrayList arListAllMsg,JArray records)
        {
            int curStep = 0;
            try
            {
                for (int i = 0; i < records.Count; i++)
                {
                    curStep++;
                    JObject jsonObjFirst = (JObject)records[i];
                    JToken roomid = jsonObjFirst["roomid"];
                    JToken from = jsonObjFirst["from"];
                    JToken msgtime = jsonObjFirst["msgtime"];
                    JToken msgtype = jsonObjFirst["msgtype"];
                    JArray tolist = jsonObjFirst["tolist"] as JArray;
                    JToken textobj = jsonObjFirst["text"];
                    JObject objText = JObject.FromObject(textobj);
                    JToken content = objText["content"];

                    WechatMsgBean wechattMsgBean = new WechatMsgBean();
                    if(roomid!=null)
                    {
                        wechattMsgBean.roomid = roomid.ToString();
                    }
                    if (from != null)
                    {
                        wechattMsgBean.from = from.ToString();
                    }
                    if (msgtime != null)
                    {
                        wechattMsgBean.msgtime = msgtime.ToString();
                    }
                    if (msgtype != null)
                    {
                        wechattMsgBean.msgtype = msgtype.ToString();
                    }
                    if (tolist != null)
                    {
                        wechattMsgBean.tolist = tolist.ToString();
                    }
                    if (content != null)
                    {
                        wechattMsgBean.content = content.ToString();
                        wechattMsgBean.content = UtilityHelp.instance.removeFirstLineTime(wechattMsgBean.content);
                    }
                    long timestamp = long.Parse(wechattMsgBean.msgtime);
                    long diffTicks =  DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond- timestamp;

                    DateTime dtSendTime = ConvertLongToDateTime(timestamp);
                    DateTime dtNow = System.DateTime.Now;
                    TimeSpan tsSend = new TimeSpan(diffTicks);
                    TimeSpan tsNow = new TimeSpan(System.DateTime.Now.Ticks);
                    TimeSpan tsDiff = dtNow - dtSendTime;
                    if(tsDiff.TotalMinutes>36)
                    {
                        continue;
                    }
                    if(!htRes.ContainsKey(wechattMsgBean.roomid))
                    {
                        ArrayList arListRoom = new ArrayList();
                        arListRoom.Add(wechattMsgBean);
                        htRes[wechattMsgBean.roomid] = arListRoom;
                    }
                    else
                    {
                        ArrayList arListRoom = htRes[wechattMsgBean.roomid] as ArrayList;
                        arListRoom.Add(wechattMsgBean);
                    }
                    arListAllMsg.Add(wechattMsgBean);






                }

            }
            catch(Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog("handleCompanyContent ex:step=" + curStep.ToString() +" "+ ex.ToString());
            }


        }


        public  DateTime ConvertLongToDateTime(long d)
        {
            DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
            if(d.ToString().Length==10)
            {
                long lTime = long.Parse(d + "0000000");
                TimeSpan toNow = new TimeSpan(lTime);
                DateTime dtResult = dtStart.Add(toNow);
                return dtResult;
            }
            else
            {
                long lTime = long.Parse(d + "0000");
                TimeSpan toNow = new TimeSpan(lTime);
                DateTime dtResult = dtStart.Add(toNow);
                return dtResult;
            }
            
        }


        public void setRoomClose(WechatMsgBean wechatMsgBean,string status)
        {
            try
            {
                Hashtable htWechatMap = new Hashtable();
                if(status.ToLower().Contains("close"))
                {
                    FrameDecoderManager.Instance.htRoomClose[wechatMsgBean.roomid] = "close";
                }
                else
                {
                    if(FrameDecoderManager.Instance.htRoomClose.ContainsKey(wechatMsgBean.roomid))
                    {
                        FrameDecoderManager.Instance.htRoomClose.Remove(wechatMsgBean.roomid);
                    }
                }

                ArrayList arListConfigs = new ArrayList();
               foreach(DictionaryEntry de in FrameDecoderManager.Instance.htRoomClose)
               {
                    arListConfigs.Add(de.Key.ToString());
               }
              logHelp.LogHelper.Instance.writeConfig(StoParams.Instance.CloseSitePath, arListConfigs);











            }
            catch (Exception ex)
            {
                LogHelper.Instance.writeLog("setRoomClose ex：" + ex.ToString());
            }
        }


        public void setUserWechat(WechatMsgBean wechatMsgBean,out string msg)
        {
            msg = "";
            try
            {
                Hashtable htWechatMap = new Hashtable();
                if(!FrameDecoderManager.Instance.htRoomUserWechat.ContainsKey(wechatMsgBean.roomid))
                {
                    FrameDecoderManager.Instance.htRoomUserWechat[wechatMsgBean.roomid] = htWechatMap;
                }
                else
                {
                    htWechatMap = FrameDecoderManager.Instance.htRoomUserWechat[wechatMsgBean.roomid] as Hashtable;
                }
                string content = wechatMsgBean.content;
                content = content.Replace("：", ":");
                content = content.Trim().Substring(content.IndexOf(":")+1);
                string[] arr = content.Split(':');
                if(arr.Length==3)
                {
                    if(arr[2].Contains(" "))
                    {
                        msg = "失败，请检查冒号数量是否等于3";
                        LogHelper.Instance.writeLog("setUserWechat 失败：" + content+" 包含空格");
                        return;
                    }
                }
                if (arr.Length != 2)
                {
                    msg = "失败，请检查冒号数量是否等于3";
                    LogHelper.Instance.writeLog("setUserWechat 失败：" + content + " 冒号不够");
                    return;
                }

                UserBean userBean = new UserBean();
                
                userBean.wechatUUID = wechatMsgBean.from;

                if (arr.Length==2)
                {
                    userBean.userName = arr[0];
                    userBean.wechat = arr[1];
                    htWechatMap[wechatMsgBean.from] = userBean;
                }
                FrameDecoderManager.Instance.htRoomUserWechat[wechatMsgBean.roomid] = htWechatMap;
                if(userBean.wechat.Length>1)
                {
                    FrameDecoderManager.Instance.htRoomDefaultWechat[wechatMsgBean.roomid] = userBean.wechat;

                    LogHelper.Instance.writeLog("wechatMsgBean.roomid：" + wechatMsgBean.roomid+" default wechat=" + userBean.wechat+ " htWechatMap from="+ wechatMsgBean.from+ " userBean.wechat="+ userBean.wechat);

                }
                
                updateRoomWechatConfig(wechatMsgBean.roomid, htWechatMap, userBean);
                if(!FrameDecoderManager.Instance.htWechatNameBean.ContainsKey(userBean.userName))
                {
                    FrameDecoderManager.Instance.htWechatNameBean[userBean.userName] = userBean;
                }
                msg = "成功";




            }
            catch(Exception ex)
            {
                msg = "失败";
                LogHelper.Instance.writeLog("setUserWechat ex：" + ex.ToString());
            }
        }
        
        public void updateRoomWechatConfig(string roomid,Hashtable htWechatMap, UserBean defaultUserBean)
        {
            try
            {
                StringBuilder sb = new StringBuilder();
                bool isFindWechat = false;
                foreach(DictionaryEntry de  in htWechatMap)
                {
                    UserBean userBean = de.Value as UserBean;
                    if(userBean.wechat!= defaultUserBean.wechat)
                    {
                        sb.AppendLine(userBean.userName + ":" + userBean.wechat + ":" + userBean.wechatUUID+":"+"");
                    }
                    else
                    {
                        sb.AppendLine(userBean.userName + ":" + userBean.wechat + ":" + userBean.wechatUUID + ":" + "default");
                    }
                    isFindWechat = true;
                }
                if(isFindWechat)
                {
                    string filePath= roomid+".txt";
                    logHelp.LogHelper.Instance.writeRoomConfig(filePath, sb.ToString());

                    LogHelper.Instance.writeLog("更新留言微信：" + sb.ToString());
                }
            }
            catch(Exception ex)
            {
                LogHelper.Instance.writeLog("updateRoomWechatConfig ex：" + ex.ToString());
            }

        }

        public bool setToken(string content,out string msg)
        {
            bool res = false;
            msg = "";
            try
            {
                if(content.Contains("content"))
                {
                    content = content.Substring(content.IndexOf("content") + 10);
                    if(content.Contains("sysResourceTree"))
                    {
                        content = content.Substring(0, content.IndexOf("sysResourceTree") - 2);
                    }
                }
                content= content.Replace("\\","");
                string wechat = "";
                logHelp.LogHelper.Instance.writeLog(content);

                logHelp.LogHelper.Instance.writeLog("开始重新设置token");

                FrameDecoderManager.Instance.resetFilter();
                if(content.Contains("token"))
                {
                    string subContent = content.Substring(content.IndexOf("loginTime") + 12);
                    string loginTime = subContent.Substring(0, subContent.IndexOf('"'));

                    subContent = subContent.Substring(subContent.IndexOf("token") + 8);
                    string token = subContent.Substring(0, subContent.IndexOf('"'));

                    subContent = subContent.Substring(subContent.IndexOf("name") + 7);
                    string name = subContent.Substring(0, subContent.IndexOf('"'));

                    subContent = subContent.Substring(subContent.IndexOf("networkId") + 11);
                    string networkId = subContent.Substring(0, subContent.IndexOf(','));
                    subContent = subContent.Substring(subContent.IndexOf("networkCode") + 14);
                    string networkCode = subContent.Substring(0, subContent.IndexOf('"'));
                    subContent = subContent.Substring(subContent.IndexOf("networkName") + 14);
                    string networkName = subContent.Substring(0, subContent.IndexOf('"'));
                    StoParams.Instance.htRegSiteNameAndToken[networkName.ToString()] = token;
                    logHelp.LogHelper.Instance.writeLog("loginTime="+ loginTime+ " token="+ token+ " name="+ name+ " networkId="+ networkId+ " networkCode="+ networkCode + " networkName=" + networkName);

                    if (!MemberInfo.Instance.htStaMap.ContainsKey(networkName.ToString()))
                    {
                        msg = networkName.ToString() + "网点未授权";
                        logHelp.LogHelper.Instance.writeLog(networkName.ToString()+"网点未授权");
                        return res;
                    }
                    if (name != null)
                    {
                        StoParams.Instance.register_user = name.ToString();
                    }
                    StoParams.Instance.register_site = networkName.ToString();
                    StoParams.Instance.register_code = networkCode.ToString();
                    StoParams.Instance.register_networkId = networkId.ToString();

                    StoParams.Instance.htRegSiteNameAndReg[networkName.ToString()]= networkId.ToString();
                    //临时网点
                    //StoParams.Instance.register_site = "金华东阳网点";
                    string strFilter = StoParams.Instance.register_site;
                    if (MemberInfo.Instance.htFilterMap.ContainsKey(networkName.ToString()))
                    {
                        strFilter = strFilter + "," + MemberInfo.Instance.htFilterMap[networkName.ToString()].ToString();
                    }
                    //DateTime dtExpireTime = Convert.ToDateTime(htStaMap[networkName.ToString()].ToString());
                    DateTime dtExpire = Convert.ToDateTime(MemberInfo.Instance.htStaMap[networkName.ToString()].ToString()); ;
                    DateTime dtLoginTime = Convert.ToDateTime(loginTime.ToString());
                    DateTime dtNow = System.DateTime.Now;
                    /*if (dtNow.Date != dtLoginTime.Date)
                    {
                        msg = networkName.ToString() + "已过期，不能使用";
                        logHelp.LogHelper.Instance.writeLog(networkName.ToString() + "已过期，不能使用");
                        return;
                    }*/
                    TimeSpan tsT = dtNow - dtLoginTime;
                    if (Math.Abs(tsT.TotalHours) > 1)
                    {
                        msg = networkName.ToString() + "系统日期不合法";
                        logHelp.LogHelper.Instance.writeLog(networkName.ToString() + "系统日期不合法");
                        return res;
                    }

                    if (dtLoginTime > dtExpire)
                    {
                        msg = networkName.ToString() + "已过期，不能使用";
                        logHelp.LogHelper.Instance.writeLog(networkName.ToString() + "已过期，不能使用");
                        return res;
                    }
                    TimeSpan ts = dtExpire - dtLoginTime;


                    if (StoParams.Instance.htWechatInfo.ContainsKey(networkName.ToString()))
                    {
                        wechat = StoParams.Instance.htWechatInfo[networkName.ToString()].ToString();
                    }
                    //recordSite(StoParams.Instance.register_site + " " + StoParams.Instance.register_code + " " + StoParams.Instance.register_user);
                    MemberInfo.Instance.token = token.ToString();
                    StoParams.Instance.htRegsiteToken[StoParams.Instance.register_user] = token.ToString();

                    RegBean regBean = new RegBean();
                    regBean.token = token.ToString();
                    regBean.regSiteName = StoParams.Instance.register_site;
                    regBean.regSiteID = networkId.ToString();
                    regBean.regSiteCode = StoParams.Instance.register_code;
                    regBean.regWechate = wechat;
                    regBean.isAnthorized = true;
                    regBean.user= name.ToString();
                    StoParams.Instance.register_wechat = wechat;
                    if (!StoParams.Instance.htRegInfo.ContainsKey(regBean.regSiteName))
                    {
                        ArrayList arListRegInfo = new ArrayList();
                        arListRegInfo.Add(regBean);
                        StoParams.Instance.htRegInfo[regBean.regSiteName] = arListRegInfo;
                    }
                    else
                    {
                        ArrayList arListRegInfo = StoParams.Instance.htRegInfo[regBean.regSiteName] as ArrayList;
                        //2323-9-7 添加,clear
                        arListRegInfo.Clear();
                        arListRegInfo.Add(regBean);
                        logHelp.LogHelper.Instance.writeLog("设置token 清空"+ regBean.regSiteName+" 之前的token");
                    }
                    //StoParams.Instance.htRegInfo[regBean.regSiteName] = regBean;
                    MemberInfo.Instance.filter = strFilter;
                    recordSiteWechat(StoParams.Instance.register_site, wechat);
                    StoParams.Instance.htWechatInfo[StoParams.Instance.register_site] = wechat;
                    StoParams.Instance.isRegByMachine = true;
                    msg = networkName.ToString() + "设置机器人在线成功";
                    res = true;
                    logHelp.LogHelper.Instance.writeLog("设置token成功 网点:"+ regBean.regSiteName+" token:"+ regBean.token+" token count="+StoParams.Instance.htRegInfo.Count.ToString());
                    ArrayList arListTokens = new ArrayList();
                    foreach (DictionaryEntry de in StoParams.Instance.htRegInfo)
                    {
                        string siteName = de.Key.ToString();
                        ArrayList arListRegBeans = (ArrayList)de.Value;
                        ArrayList arListDel = new ArrayList();
                        foreach (RegBean crregBean in arListRegBeans)
                        {
                            if (crregBean.errorTimes > 30)
                            {
                                arListDel.Add(crregBean);
                            }
                            else
                            {
                                string tokenCur = crregBean.token;
                                string regSiteID = crregBean.regSiteID;
                                string regSiteCode = crregBean.regSiteCode;
                                string regWechate = crregBean.regWechate;
                                string user = crregBean.user;
                                StoParams.Instance.htTokenUser[tokenCur] = user;
                                string addLine = tokenCur + "$" + siteName + "$" + regSiteID + "$" + regSiteCode + "$" + regWechate+"$"+user;
                                arListTokens.Add(addLine);
                            }

                        }
                        foreach (RegBean curregBean in arListDel)
                        {
                            if (arListRegBeans.Contains(curregBean))
                            {
                                arListRegBeans.Remove(curregBean);
                            }
                        }
                        //RegBean regBean = (RegBean)de.Value;


                    }

                    if (arListTokens.Count > 0)
                    {
                        logHelp.LogHelper.Instance.writeConfig(StoParams.Instance.TokenSitePath, arListTokens);
                    }
                    FrameDecoderManager.Instance.isFirstLoginToken = true;


                }
            }
            catch(Exception ex)
            {
                msg = "设置token失败 ex:" + ex.ToString();
                logHelp.LogHelper.Instance.writeLog("设置token失败 ex:" + ex.ToString());
            }
            return res;
        }


        public void recordSiteWechat(string siteName, string wechat)
        {
            try
            {
                string delFile = System.Environment.CurrentDirectory + "\\" + StoParams.Instance.SiteWechatPath;
                File.Delete(delFile);
                FileStream bFile = new FileStream(delFile, FileMode.Append);
                StreamWriter swb = null;
                if (swb == null)
                {
                    swb = new StreamWriter(bFile);
                }
                swb.WriteLine(siteName + " " + wechat);
                swb.Close();

            }
            catch (Exception ex)
            {

            }
        }

        public string getErrorMsg(string errorCode)
        {
            string res = "";
            try
            {
                switch(errorCode)
                {
                    case "811":
                        res = "服务关闭";
                        break;
                    case "812":
                        res = "服务暂停";
                        break;
                    case "813":
                        res = "运单编号过长";
                        break;
                    case "814":
                        res = "重量输入有误";
                        break;
                    case "820":
                        res = "订单已取消";
                        break;
                    case "821":
                        res = "单号不符合规则";
                        break;
                    case "200":
                        res = "揽收成功";
                        break;

                }

            }
            catch(Exception ex)
            {

            }
            return res;

        }



        public ArrayList getStaticListAuto(Hashtable htInterceptNoMap,Hashtable htChageAddrNoMap,Hashtable htInterceptSucess)
        {
            ArrayList arListNoMap = new ArrayList();

            ArrayList arListRes = new ArrayList();
            try
            {
                string dir = System.Environment.CurrentDirectory + "\\log";
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                //判断文件是否存在，不存在则创建的存在
                string sPath = dir;
                ArrayList arListTotal = new ArrayList();
                for(int i=10;i>=0;i--)
                {
                    string date = System.DateTime.Now.AddDays(0-i).ToString("yyyy-MM-dd"); ;
                    sPath = Path.Combine(dir, date + "-static.txt");
                    //System.Windows.Forms.MessageBox.Show("sPath:" + sPath);
                    if (!File.Exists(sPath))
                    {
                        logHelp.LogHelper.Instance.writeLog(sPath + "文件不存在");
                        continue;
                    }

                    ArrayList arListTmp = UtilityHelp.Instance.getArrayLineAuto(sPath);
                    arListTotal.AddRange(arListTmp);
                }
                


                foreach (string strLine in arListTotal)
                {

                    TimeSpan ts = System.DateTime.Now - FrameDecoderManager.Instance.dtLastMsg;
                  
                    if(ts.TotalMinutes<3&&!FrameDecoderManager.Instance.isFirstLoginToken)
                    {
                        break;
                    }

                   
                    if (strLine.Contains("拦截无物流")|| strLine.Contains("订单取消"))
                    {
                        string[] arr = strLine.Split('$');
                        if(arr.Length<4)
                        {
                            continue;
                        }
                        string type = arr[0];
                        string barcode= arr[1];
                        string wechatName = arr[2];
                        string addr = "";
                        string lanshouTime = "";
                        string roomid = "";

                        string fromWxID = "";
                        if (arr.Length>=5)
                        {
                            if(arr[4].Length>10)
                            {
                                addr = arr[4];
                            }
                            lanshouTime= arr[3];
                        }
                        if (arr.Length >= 6)
                        {
                            roomid= arr[5];
                        }

                        if (arr.Length >= 7)
                        {
                            fromWxID = arr[6];
                        }
                        if (wechatName=="")
                        {
                            continue;
                        }
                        if(!FrameDecoderManager.Instance.htWechatNameBean.ContainsKey(wechatName))
                        {
                            //logHelp.LogHelper.Instance.writeLog("用户：" + wechatName + " 找不到对应配置 对应单号："+ barcode);
                            //continue;
                        }

                        ArrayList arListAllGXTask = new ArrayList();
                        string httpRes = "";
                        ArrayList arListRoadMap = JTDelayHelper.Instance.getRoadMap(barcode, out httpRes, arListAllGXTask);
                        if (arListRoadMap.Count == 0)
                        {
                            continue;
                        }
                        if(Utility.isTaskDone(arListRoadMap, "拦截件"))
                        {
                            continue;
                        }

                        if (Utility.isOnlyPackRoadmap(arListRoadMap))
                        {
                            continue;
                        }
                        if (!Utility.isMySiteParcel(arListRoadMap))
                        {
                            continue;
                        }
                        UserBean userBean = FrameDecoderManager.Instance.htWechatNameBean[wechatName] as UserBean;
                        if(userBean==null)
                        {
                            userBean = new UserBean();
                        }
                        ParcelBean parcelBean = new ParcelBean();
                        parcelBean.taskType = "自动拦截";
                        parcelBean.ori_addr = addr;
                        parcelBean.wayBill = barcode;
                        parcelBean.senderWeChat = wechatName;
                        parcelBean.wechat = userBean.wechat;
                        parcelBean.lanshouTime = lanshouTime;
                        parcelBean.roomID = roomid;
                        parcelBean.fromWxID = fromWxID;
                        if (roomid!="")
                        {
                            parcelBean.isSuperWay = true;
                        }
                        htInterceptNoMap[barcode] = parcelBean;
                        if(!arListNoMap.Contains(barcode))
                        {
                            arListNoMap.Add(barcode);
                        }                       
                        
                    }
                    else
                    {
                        if (strLine.Contains("拦截"))
                        {
                            string[] arr = strLine.Split('$');
                            if (arr.Length < 4)
                            {
                                continue;
                            }
                            string type = arr[0];
                            string barcode = arr[1];
                            if(type.EndsWith("拦截"))
                            {
                                ArrayList arListAllGXTask = new ArrayList();
                                string httpRes = "";
                                ArrayList arListRoadMap = JTDelayHelper.Instance.getRoadMap(barcode, out httpRes, arListAllGXTask);

                                if (excuteSuccess(arListRoadMap, "拦截"))
                                {
                                    if (htInterceptNoMap.ContainsKey(barcode))
                                    {
                                        htInterceptNoMap.Remove(barcode);
                                    }
                                    if (arListNoMap.Contains(barcode))
                                    {
                                        arListNoMap.Remove(barcode);
                                    }
                                }
                                
                            }

                            if (type.EndsWith("取消拦截"))
                            {
                                
                                if (htInterceptNoMap.ContainsKey(barcode))
                                {
                                    htInterceptNoMap.Remove(barcode);
                                }
                                if (arListNoMap.Contains(barcode))
                                {
                                    arListNoMap.Remove(barcode);
                                }
                            }

                            


                        }
                    }
                    
                   
                }


                foreach (string strLine in arListTotal)
                {
                    if (strLine.Contains("改地址无物流")||strLine.Contains("改地址未出"))
                    {
                        string[] arr = strLine.Split('$');
                        if (arr.Length < 4)
                        {
                            continue;
                        }
                        string type = arr[0];
                        string barcode = arr[1];
                        string wechatName = arr[2];
                        string addr = "";
                        string roomid = "";
                        string fromWxID = "";
                        if (arr.Length >= 5)
                        {
                            if (arr[4].Length > 10)
                            {
                                addr = arr[4];
                            }
                        }

                        if(addr=="")
                        {
                            continue;
                        }
                        if (arr.Length >= 6)
                        {
                            roomid = arr[5];
                        }

                        if (arr.Length >= 7)
                        {
                            fromWxID = arr[6];
                        }
                        if (!FrameDecoderManager.Instance.htWechatNameBean.ContainsKey(wechatName))
                        {
                            //logHelp.LogHelper.Instance.writeLog("用户：" + wechatName + " 找不到对应配置 对应单号：" + barcode);
                            //continue;
                        }

                        ArrayList arListAllGXTask = new ArrayList();
                        string httpRes = "";
                        string jisanSite = "";
                        ArrayList arListRoadMap = JTDelayHelper.Instance.getRoadMap(barcode, out httpRes, arListAllGXTask);
                        if (arListRoadMap.Count == 0)
                        {
                            continue;
                        }
                        if (!JTDelayHelper.Instance.canChageAddr(arListRoadMap, out jisanSite))
                        {
                            continue;


                        }
                        if (Utility.isTaskDone(arListRoadMap, "改地址"))
                        {
                            continue;
                        }

                        if (!Utility.isMySiteParcel(arListRoadMap))
                        {
                            continue;
                        }

                        UserBean userBean = FrameDecoderManager.Instance.htWechatNameBean[wechatName] as UserBean;
                        if(userBean==null)
                        {
                            userBean = new UserBean();
                        }
                        ParcelBean parcelBean = new ParcelBean();
                        parcelBean.taskType = "自动改地址";
                        parcelBean.ori_addr = addr;
                        parcelBean.wayBill = barcode;
                        parcelBean.senderWeChat = wechatName;
                        parcelBean.wechat = userBean.wechat;
                        parcelBean.fromWxID = fromWxID;

                        parcelBean.roomID = roomid;
                        if (roomid != "")
                        {
                            parcelBean.isSuperWay = true;
                        }

                        htChageAddrNoMap[barcode] = parcelBean;
                        if (!arListNoMap.Contains(barcode))
                        {
                            arListNoMap.Add(barcode);
                        }
                            
                    }
                    else
                    {
                        if (strLine.Contains("改地址"))
                        {
                            string[] arr = strLine.Split('$');
                            if (arr.Length < 4)
                            {
                                continue;
                            }
                            string type = arr[0];
                            string barcode = arr[1];
                            if (type.EndsWith("改地址") && htChageAddrNoMap.ContainsKey(barcode))
                            {
                                htChageAddrNoMap.Remove(barcode);
                                if(arListNoMap.Contains(barcode))
                                {
                                    arListNoMap.Remove(barcode);
                                }
                            }
                        }
                    }

                }



                try
                {
                    foreach (string strLine in arListTotal)
                    {
                        TimeSpan ts = System.DateTime.Now - FrameDecoderManager.Instance.dtLastMsg;
                        if (ts.TotalMinutes < 3)
                        {
                            break;
                        }
                        if (strLine.Contains("拦截"))
                        {
                            string[] arr = strLine.Split('$');
                            if (arr.Length < 4)
                            {
                                continue;
                            }
                            string type = arr[0];
                            string barcode = arr[1];
                            string wechatName = arr[2];
                            string addr = "";
                            string lanshouTime = "";
                            string roomid = "";
                            string taskTime = "";
                            if(arr[arr.Length-2].Contains(":")&& arr[arr.Length - 2].Contains("-"))
                            {
                                taskTime = arr[arr.Length - 2];
                            }
                            if (arr.Length >= 5)
                            {
                                if (arr[4].Length > 10)
                                {
                                    addr = arr[4];
                                }
                                lanshouTime= arr[3];
                            }
                            if (arr.Length >= 6)
                            {
                                roomid = arr[5];
                            }
                            /*if (!FrameDecoderManager.Instance.htWechatNameBean.ContainsKey(wechatName))
                            {
                                //logHelp.LogHelper.Instance.writeLog("用户：" + wechatName + " 找不到对应配置");
                                continue;
                            }*/

                            ArrayList arListAllGXTask = new ArrayList();
                            string httpRes = "";


                            if (type == "拦截" || type == "自动拦截")
                            {
                                UserBean userBean = FrameDecoderManager.Instance.htWechatNameBean[wechatName] as UserBean;
                                if(userBean==null)
                                {
                                    userBean = new UserBean();
                                }
                                ParcelBean parcelBean = new ParcelBean();
                                parcelBean.taskType = "拦截签收统计";
                                parcelBean.ori_addr = addr;
                                parcelBean.wayBill = barcode;
                                parcelBean.senderWeChat = wechatName;
                                parcelBean.wechat = userBean.wechat;
                                parcelBean.lanshouTime = lanshouTime;
                                parcelBean.roomID = roomid;
                                parcelBean.queryTaskTime = taskTime;
                                htInterceptSucess[barcode] = parcelBean;

                            }
                            else if (type == "取消拦截")
                            {
                                if (htInterceptSucess.ContainsKey(barcode))
                                {
                                    htInterceptSucess.Remove(barcode);
                                }
                            }

                        }



                    }
                }
                catch(Exception ex)
                {

                }



                






            }

            catch (Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog("发生异常：" + ex.ToString());
            }
            return arListNoMap;
        }


        private bool excuteSuccess(ArrayList arListRoadMap,string task)
        {
            bool res = false;
            try
            {
                string keyWrods = "转寄登记";
                if (task.Contains("拦截"))
                {
                    keyWrods = "拦截件登记";
                }
                foreach (RoadBean road in arListRoadMap)
                {
                    if (road.scanTypeName.Contains(keyWrods))
                    {
                        res = true;
                        break;
                    }
                }

            }
            catch (Exception e)
            {

            }
            return res;

        }



        public void getSecondType(ArrayList arListRoadMap, string firstType,SecondTypeBean secondTypeBean)
        {

            try
            {
                

            }
            catch(Exception ex)
            {

            }
        }


        public bool hasSiteDoArriva(ArrayList arListRoadMap)
        {
            bool res = false;
            try
            {
                for (int i = arListRoadMap.Count - 1; i > 2; i--)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    string scanSite = roadBean.scanNetworkName;
                    if (scanSite != StoParams.Instance.register_site && scanSite.Contains("网点")&& roadBean.scanTypeName== "卸车到件")
                    {
                        res = true;
                    }
                }
            }
            catch(Exception ex)
            {

            }
            return res;
        }

        public RoadBean  getLastValidScanRoadBean(ArrayList arListRoadMap,string regSite)
        {
            RoadBean roadBean = new RoadBean();
            try
            {
                for (int i = arListRoadMap.Count-1; i >0; i--)
                {
                    roadBean = (RoadBean)arListRoadMap[i];
                    string scanSite = roadBean.scanNetworkName;
                    if(scanSite!= regSite&& (!roadBean.scanTypeName.Contains("问题件")&& !roadBean.scanTypeName.Contains("退件") && !roadBean.scanTypeName.Contains("拦截件") && !roadBean.scanTypeName.Contains("完结")))
                    {
                        return roadBean;
                    }
                }

            }
            catch(Exception ex)
            {

            }
            return roadBean;
        }



        public bool isFinishedOverTime(ArrayList arListRoadMap, string regSite)
        {
            bool res = false;
            RoadBean roadBean = new RoadBean();
            try
            {
                for (int i = arListRoadMap.Count - 1; i > 0; i--)
                {
                    roadBean = (RoadBean)arListRoadMap[i];
                    string scanSite = roadBean.scanNetworkName;
                    if (scanSite != regSite && (!roadBean.scanTypeName.Contains("完结")))
                    {
                        res = true;
                        break;
                    }
                }

            }
            catch (Exception ex)
            {

            }
            return res;
        }




        public void parseSecondTypeYishiAndDelay(ArrayList arListRoadMap, string firstType, SecondTypeBean secondTypeBean,string regSite)
        {

            string commentType = "";
            bool isLastInWh = false;
            try
            {
                if(firstType.Contains("延误"))
                {
                    secondTypeBean.name = "末端网点未及时到件";
                    secondTypeBean.code = "0111";                    
                    if (hasSiteDoArriva(arListRoadMap))
                    {
                        secondTypeBean.name = "派件延误";
                        secondTypeBean.code = "0101";
                    }
                    
                    return;
                }
                RoadBean road = getLastValidScanRoadBean(arListRoadMap, regSite);
                if(road.scanNetworkName=="")
                {
                    if (road.scanTypeName.Contains("快件取出扫描")|| road.scanTypeName.Contains("入库扫描"))
                    {
                        secondTypeBean.name = "网点到件遗失";
                        secondTypeBean.code = "0319";
                        return;
                    }
                }
                

                string status = road.status;
                if (status.Contains("已签收")|| road.waybillTrackingContent.Contains("已签收"))
                {
                    secondTypeBean.name = "签收未收到（非第三方";
                    secondTypeBean.code = "0318";
                    if(StoParams.Instance.register_site.Contains("江门")||StoParams.Instance.register_site.Contains("邓岗网点"))
                    {
                        if ((road.waybillTrackingContent.Contains("凭取件码签收") || road.waybillTrackingContent.Contains("代收点")) && road.scanNetworkName.Contains("网点") && road.scanNetworkName != StoParams.Instance.register_site)
                        {
                            secondTypeBean.name = "入第三方驿站后遗失";
                            secondTypeBean.code = "0317";
                        }
                    }
                     
                    return;
                }


                if (road.scanNetworkName.Contains("中心")|| road.scanNetworkName.Contains("分拨"))
                {
                    if (road.scanTypeName.Contains("到件"))
                    {
                        secondTypeBean.name = "中心到件遗失";
                        secondTypeBean.code = "0310";
                    }

                    if (road.scanTypeName.Contains("发件"))
                    {
                        if (road.nextStopName.Contains("网点")|| road.nextStopName.Contains("集散") || road.nextStopName.Contains("营业部"))
                        {
                            secondTypeBean.name = "中心发网点/集散遗失";
                            secondTypeBean.code = "0320";
                        }

                        else if (road.nextStopName.Contains("中心")|| road.nextStopName.Contains("分拨"))
                        {
                            secondTypeBean.name = "中心发中心遗失";
                            secondTypeBean.code = "0309";
                        }
                    }
                }

                else if (road.scanNetworkName.Contains("集散"))
                {
                    if(road.scanTypeName.Contains("到件"))
                    {
                        secondTypeBean.name = "集散到件遗失";
                        secondTypeBean.code = "0307";
                    }

                    if (road.scanTypeName.Contains("发件"))
                    {
                        if(road.nextStopName.Contains("网点"))
                        {
                            secondTypeBean.name = "集散点发网点遗失";
                            secondTypeBean.code = "0322";
                        }

                        if (road.nextStopName.Contains("中心")|| road.nextStopName.Contains("分拨"))
                        {
                            secondTypeBean.name = "网点/集散发中心遗失";
                            secondTypeBean.code = "0321";
                        }
                    }
                }


                else if (road.scanNetworkName.Contains("网点"))
                {
                   
                    if (road.scanTypeName.Contains("到件"))
                    {
                        secondTypeBean.name = "网点到件遗失";
                        secondTypeBean.code = "0319";
                    }
                    else if (road.scanTypeName.Contains("签收") || road.status.Contains("已签收") || road.waybillTrackingContent.Contains("已签收"))
                    {
                        secondTypeBean.name = "签收未收到（非第三方";
                        secondTypeBean.code = "0318";
                    }
                    else if ((road.waybillTrackingContent.Contains("凭取件码签收") || road.waybillTrackingContent.Contains("代收点")) && road.scanNetworkName.Contains("网点") && road.scanNetworkName != StoParams.Instance.register_site)
                    {
                        secondTypeBean.name = "入第三方驿站后遗失";
                        secondTypeBean.code = "0317";
                    }
                   

                    else if ((road.scanTypeName == "入仓扫描" || road.scanTypeName == "入库扫描") && road.scanNetworkName.Contains("网点") && road.scanNetworkName != StoParams.Instance.register_site)
                    {
                        secondTypeBean.name = "入第三方驿站后遗失";
                        secondTypeBean.code = "0317";
                    }


                    else if (road.scanTypeName.Contains("发件"))
                    {                        

                        if (road.nextStopName.Contains("中心") || road.nextStopName.Contains("分拨"))
                        {
                            secondTypeBean.name = "网点/集散点发中心后无记录";
                            secondTypeBean.code = "0321";
                        }

                        if (road.nextStopName.Contains("集散"))
                        {
                            secondTypeBean.name = "网点发集散点遗失";
                            secondTypeBean.code = "0323";
                        }
                    }
                    else
                    {
                        if (road.status.Contains("派件中"))
                        {
                            if (road.scanTypeName == "出仓扫描" || road.scanTypeName == "出库扫描")
                            {
                                commentType = "派件";
                            }
                           
                        }
                        if (road.status.Contains("已签收"))
                        {
                            commentType = "签收";
                        }
                        else if (road.scanTypeName == "问题件扫描" && road.scanNetworkName.Contains("网点") && road.scanNetworkName != StoParams.Instance.register_site)
                        {
                            commentType = "派件";
                        }
                      
                        else if (road.scanTypeName == "快件取出扫描" && road.scanNetworkName.Contains("网点") && road.scanNetworkName != StoParams.Instance.register_site)
                        {
                            commentType = "派件";
                        }
                        else if ((road.scanTypeName == "入仓扫描" || road.scanTypeName == "入库扫描") && road.scanNetworkName.Contains("网点") && road.scanNetworkName != StoParams.Instance.register_site)
                        {
                            isLastInWh = true;
                            commentType = "派件";
                        }
                        else if ((road.scanTypeName == "出仓扫描" || road.scanTypeName == "出库扫描") && road.scanNetworkName.Contains("网点") && road.scanNetworkName != StoParams.Instance.register_site)
                        {
                            commentType = "派件";
                        }
                        else if (road.scanTypeName == "完结" && road.scanNetworkName.Contains("网点") && road.scanNetworkName != StoParams.Instance.register_site && road.waybillTrackingContent.Contains("超时未签收"))
                        {
                            commentType = "派件";
                        }

                        if(commentType.Contains("派件"))
                        {
                            secondTypeBean.name = "派送途中遗失";
                            secondTypeBean.code = "0316";
                        }

                        if(secondTypeBean.name=="")
                        {
                            secondTypeBean.name = "派送途中遗失";
                            secondTypeBean.code = "0316";
                        }
                    }
                }



            }
            catch (Exception ex)
            {

            }

        }



        public bool isNeedToTransferKF(string addr)
        {
            bool res = false;
            try
            {
                if(addr.Contains("转客服")|| addr.Contains("为什么退回") ||addr.Contains("怎么退回")
                    || addr.Contains("为何退回") || addr.Contains("人工") || addr.Contains("怎么没") || addr.Contains("是不是")
                    || addr.Contains("傻逼") || addr.Contains("他妈的") || addr.Contains("有病") || addr.Contains("电话无人接听或关机")
                    || addr.Contains("未开箱无理由拒收") || addr.Contains("自提未取")
                    || addr.Contains("是否退回") || addr.Contains("截回情况")
                    || addr.Contains("截回到哪") || addr.Contains("退回到哪")
                    || addr.Contains("截回进度") || addr.Contains("退回进度")
                    || addr.Contains("退回了吗") || addr.Contains("退款情况")
                    || addr.Contains("有没有退回") || addr.Contains("退回了没")
                    || addr.Contains("拦截了吗") || addr.Contains("拦截情况")
                    || addr.Contains("是否拦截") || addr.Contains("有没有拦截")
                    || addr.Contains("是否已经退回") || addr.Contains("为何拦截"))
                {
                    res = true;
                }
            }
            catch(Exception ex)
            {

            }
            return res;
        }


        public bool isQiasnshouWeiDao(string addr)
        {
            bool res = false;
            try
            {
                if (addr.Contains("未收到") || addr.Contains("没收到") || addr.Contains("未找到") || addr.Contains("没找到") || addr.Contains("没有找到") || addr.Contains("没有收到") || addr.Contains("签收未到") || addr.Contains("派送")
                    || addr.Contains("签收未收") || addr.Contains("签收未收到") || addr.Contains("破损") || addr.Contains("短少") || addr.Contains("污染") || addr.Contains("虚假签收")||addr.Contains("签收没有收到")
                    || addr.Contains("签收没收到") || addr.Contains("签收未收到") || addr.Contains("签收未签收") || addr.Contains("签收证明") || addr.Contains("提供签收底单") || addr.Contains("未收到2小时提供签收底单")
                    || addr.Contains("客户说没有收到") || addr.Contains("2小时提供签收底单") || addr.Contains("客户说没有收到") || addr.Contains("客户没收到提供签收底单")
                    || addr.Contains("签未收") || addr.Contains("签收底单") || addr.Contains("核实签收") || addr.Contains("此件客户没收到")
                    || addr.Contains("地址错误") || addr.Contains("派送位置错误") || addr.Contains("送错地址") || addr.Contains("地址不对") || addr.Contains("继续派送") || addr.Contains("重新派送")
                    || addr.Contains("电联丢件") || addr.Contains("顾客未收到") || addr.Contains("核实签收") || addr.Contains("麻烦核实") || addr.Contains("续送")||addr.Contains("断更"))
                {
                    res = true;
                }
                if (addr.Replace(" ", "").Contains("改电话") || addr.Replace(" ", "").Contains("改收件人电话")
                            || addr.Replace(" ", "").Contains("改收货人电话") || addr.Replace(" ", "").Contains("改联系电话")
                            || addr.Replace(" ", "").Contains("改联系人电话")
                            || addr.Replace(" ", "").Contains("电话修改为")
                            || addr.Replace(" ", "").Contains("电话改为")
                            || addr.Replace(" ", "").Contains("新电话号码")

                            || addr.Replace(" ", "").Contains("电话换成")
                            || addr.Replace(" ", "").Contains("电话换为")
                            || addr.Replace(" ", "").Contains("号码改为")
                            || addr.Replace(" ", "").Contains("电话变为")
                            || addr.Replace(" ", "").Contains("手机修改为")
                             || addr.Replace(" ", "").Contains("号码修改为")
                            || UtilityHelp.Instance.isBingoMainTxt(addr, "改", "电话", 5)
                            || UtilityHelp.Instance.isBingoMainTxt(addr, "改", "号码", 5))
                {
                    res = true;
                }
            }
            catch (Exception ex)
            {

            }
            return res;
        }


        public bool isCuiAddr(string addr)
        {
            bool res = false;
            try
            {
                if (addr.Contains("未更新") || addr.Contains("没更新") || addr.Contains("催下更新") || addr.Contains("催更新")
                    || addr.Contains("无物流") || addr.Contains("催更") || addr.Contains("加紧送达") || addr.Contains("给我转人工")
                    || addr.Contains("没有物流") || addr.Contains("催快递") || addr.Contains("没动静") || addr.Contains("尽快派送")
                    || addr.Contains("催单") || addr.Contains("催下") || addr.Contains("催物流") || addr.Contains("催送件") || addr.Contains("丢件")
                     || addr.Contains("速派送") || addr.Contains("尽快更新") || addr.Contains("加急") || addr.Contains("没有更新物流")
                      || addr.Contains("卡件") || addr.Contains("物流异常") || addr.Contains("停滞") || addr.Contains("催促")
                        || addr.Contains("催促派送") || addr.Contains("中转超时") || addr.Contains("核实催件") || addr.Contains("催促")
                    || addr.Contains("急用") || addr.Contains("催派") || addr.Contains("催更新") || addr.Contains("催一下") || addr.Contains("送货上门")
                    || addr.Contains("物流断更") || addr.Contains("物流没更新") || addr.Contains("物流一直不更新") || addr.Contains("联系派送"))
                {
                    res = true;
                }
            }
            catch (Exception ex)
            {

            }
            return res;
        }



        public bool isInterceptAddr(string addr)
        {
            bool res = false;
            try
            {
                if (addr.Contains("不要了") || addr.Contains("已退款") || addr.Contains("催退")
                    || addr.Contains("已退款成功") || addr.Contains("客户拒收") || addr.Contains("加急退回"))
                {
                    res = true;
                }
            }
            catch (Exception ex)
            {

            }
            return res;
        }



        private string sec_to_hms(long duration)
        {
            TimeSpan ts = new TimeSpan(0, 0, Convert.ToInt32(duration));
            string str = "";
            if (ts.Hours > 0)
            {
                str = String.Format("{0:00}", ts.Hours) + ":" + String.Format("{0:00}", ts.Minutes);
            }
            if (ts.Hours == 0 && ts.Minutes > 0)
            {
                str = "00:" + String.Format("{0:00}", ts.Minutes) ;
            }
 
            return str;
        }

        public string getHourMinuteTime(string operatime)
        {
            string res = operatime;
            try
            {
                if(res!=""&& res!="0")
                {
                    long seconds = Convert.ToInt32(operatime) * 60*60;
                    res = sec_to_hms(seconds);
                }

            }
            catch(Exception ex)
            {

            }
            return res;
        }


        public string getStaticText(string[] artListBarcodes)
        {
            string res = "";
            try
            {
                ArrayList arListTmp = new ArrayList();
                Hashtable htStatic = new Hashtable();
                foreach (string strBarCode in artListBarcodes)
                {
                    string msg = "";
                    ArrayList arListRoadGX = new ArrayList();
                    ArrayList arListRoadMap = JTDelayHelperNew.Instance.getRoadMap(strBarCode.Trim(), out msg, arListRoadGX);
                    handleDiffertntSite(htStatic, arListRoadMap);
                }
                int total = 0;
                foreach(DictionaryEntry de in htStatic)
                {
                    total = total + Convert.ToInt32(de.Value);
                }

                foreach (DictionaryEntry de in htStatic)
                {
                    double percent = Convert.ToDouble(de.Value) / Convert.ToDouble(total);
                    string result = percent.ToString("0%");//得到6%

                    res = res + de.Key.ToString() + " 揽收量：" + de.Value.ToString() + " 占比:" + result + " ";
                    //total = total + Convert.ToInt32(de.Value);
                }
                res = res + " 总量:" + total.ToString();



            }
            catch (Exception ex)
            {

            }
            return res;

        }

        public void handleDiffertntSite(Hashtable htSiteStatic, ArrayList arListRoadMap)
        {
            try
            {
                foreach(RoadBean roadBean in arListRoadMap)
                {
                    string site = roadBean.scanNetworkName;
                    string type = roadBean.scanTypeName;
                    if(type.Contains("揽收"))
                    {
                        if(!htSiteStatic.ContainsKey(site))
                        {
                            htSiteStatic[site] = 1;
                        }
                        else
                        {
                            htSiteStatic[site] = Convert.ToInt32(htSiteStatic[site]) + 1;
                        }
                        break;
                    }
                }

            }
            catch(Exception ex)
            {

            }

        }


        public bool isTimeLine(string curLine)
        {
            bool res = false;
            try
            {
                string[] curLineArr = curLine.Split(' ');
                if(curLineArr[curLineArr.Length-1].Contains(":"))
                {
                    DateTime dt = Convert.ToDateTime(curLineArr[curLineArr.Length - 1]);
                    res = true;

                }
            }
            catch(Exception ex)
            {

            }
            return res;
        }

        public bool isValidLine(string strLine)
        {
            bool res = true;
            try
            {
                if (strLine.Contains("提到了"))
                {
                    res=false;
                }
                if (strLine.Contains("踢出"))
                {
                    res = false;
                }
                if (strLine.Contains("拍了"))
                {
                    res = false;
                }
                if (strLine.Contains("回复:"))
                {
                    res = false;
                }
                if (strLine.Contains("条新消息"))
                {
                    res = false;
                }
                if (strLine.Contains("以下是新消息"))
                {
                    strLine = strLine.Replace("以下是新消息", "");
                }
                if (strLine.Contains("加入企业用户创建的群"))
                {
                    res = false;
                }
                if (strLine.Contains("加入了本群"))
                {
                    res = false;
                }
                if (strLine.Contains("好友"))
                {
                    res = false;
                }
            }
            catch(Exception ex)
            {

            }
            return res;

        }

        public ArrayList GetSeperateMsgBean(string content, GroupPos curGroupPos)
        {
            ArrayList arListRes = new ArrayList();
            try
            {
                if(curGroupPos.lastTimeHandleLine!="")
                {
                    if(content.Contains(curGroupPos.lastTimeHandleLine))
                    {
                        content = content.Substring(content.IndexOf(curGroupPos.lastTimeHandleLine) + curGroupPos.lastTimeHandleLine.Length);
                    }
                }

                string[] arrAllContent = content.Split('\n');
                int timeLineIndex = 0;
                for(int i=0;i< arrAllContent.Length;i++)
                {
                    timeLineIndex = i;
                    if (isTimeLine(arrAllContent[i]))
                    {
                        break;
                    }
                }
                bool findValidTimeLine = false;
                for(int i= timeLineIndex;i< arrAllContent.Length; i++)
                {
                    if (isTimeLine(arrAllContent[i]))
                    {
                        string[] arr = arrAllContent[i].Split(' ');
                        DateTime dtCurLine=System.DateTime.Now;
                        bool findTime = false;

                        arrAllContent[i] = arrAllContent[i].Replace("/", "-");
                        if (arr[0]== curGroupPos.replyUser)
                        {
                            findTime = false;
                        }
                        else if (arrAllContent[i].Contains("-")&& arrAllContent[i].Contains(":"))
                        {
                            dtCurLine = Convert.ToDateTime(arr[arr.Length - 2] + " " + arr[arr.Length - 1]);
                            findTime = true;
                        }
                        else if(!arrAllContent[i].Contains("-") && arrAllContent[i].Contains(":"))
                        {
                            dtCurLine = Convert.ToDateTime(arr[arr.Length - 1]);
                            findTime = true;
                        }
                        if(findTime)
                        {
                            if (dtCurLine < curGroupPos.lastHandledTime)
                            {
                                findValidTimeLine = false;
                                
                            }
                            else
                            {
                                findValidTimeLine = true;
                                WechatMsgBean wechattMsgBean = new WechatMsgBean();
                                wechattMsgBean.from = arr[0];
                                wechattMsgBean.fromWechat = arr[0];
                                curGroupPos.lastHandledTime = dtCurLine;
                                curGroupPos.lastTimeHandleLine = arrAllContent[i];
                                arListRes.Add(wechattMsgBean);
                            }
                            continue;

                        }




                    }
                    if(!findValidTimeLine)
                    {
                        continue;
                    }
                    if(arListRes.Count==0)
                    {
                        continue;
                    }

                    if(!isValidLine(arrAllContent[i]))
                    {
                        continue;
                    }
                    WechatMsgBean lastMsgBean = (WechatMsgBean)arListRes[arListRes.Count - 1];
                    lastMsgBean.content = lastMsgBean.content + "\n" + arrAllContent[i];


                }

            }
            catch(Exception ex)
            {

            }
            return arListRes;
        }



        public bool isCenterReturnDelay(string regInterCeptTime, string terMinalLeaver, ResultBean resultBean, string interCeptScanSite)
        {
            bool res = false;
            try
            {
                if (regInterCeptTime.StartsWith("000"))
                {
                    return false;
                }

                if (regInterCeptTime != "" && terMinalLeaver != "")
                {
                    DateTime dtRegInterScan = Convert.ToDateTime(Convert.ToDateTime(regInterCeptTime).ToShortDateString());
                    DateTime dtrMinalLeaver = Convert.ToDateTime(Convert.ToDateTime(terMinalLeaver).ToShortDateString());
                    TimeSpan ts = dtrMinalLeaver - dtRegInterScan;
                    if (Math.Abs(ts.TotalDays) <= 1)
                    {
                        return false;
                    }
                    res = true;
                    resultBean.dutySite = interCeptScanSite;
                    resultBean.errorType = "退回延误";
                    resultBean.delayDays = ((int)(ts.TotalDays) - 1).ToString();

                    if (ts.TotalDays >= 7)
                    {
                        resultBean.dutySite = interCeptScanSite;
                        resultBean.errorType = "彻底延误";
                        resultBean.delayDays = ((int)(ts.TotalDays) - 1).ToString();
                    }

                    return true;


                }
            }
            catch (Exception ex)
            {

            }
            return res;
        }


        public bool isReturnDelay(string regInterCeptTime,string terMinalLeaver,ResultBean resultBean,string interCeptScanSite)
        {
            bool res = false;
            try
            {
                int standard = 1;
                if(interCeptScanSite.Contains("转运")|| interCeptScanSite.Contains("分拨"))
                {
                    DateTime dtInterCept = Convert.ToDateTime(regInterCeptTime);
                    if(dtInterCept.Hour>=18)
                    {
                        standard = 2;
                    }
                }
                if(regInterCeptTime.StartsWith("000"))
                {
                    return false;
                }
                if (regInterCeptTime != "" && terMinalLeaver != "")
                {
                    DateTime dtRegInterScan = Convert.ToDateTime(Convert.ToDateTime(regInterCeptTime).ToShortDateString());
                    DateTime dtrMinalLeaver = Convert.ToDateTime(Convert.ToDateTime(terMinalLeaver).ToShortDateString());
                    TimeSpan ts = dtrMinalLeaver - dtRegInterScan;
                    if (Math.Abs(ts.TotalDays) <= standard)
                    {
                        return false;
                    }
                    res = true;
                    resultBean.dutySite = interCeptScanSite;
                    resultBean.errorType = "退回延误";
                    resultBean.delayDays = ((int)(ts.TotalDays) - 1).ToString();

                    if(ts.TotalDays>=7)
                    {
                        resultBean.dutySite = interCeptScanSite;
                        resultBean.errorType = "彻底延误";
                        resultBean.delayDays = ((int)(ts.TotalDays) - 1).ToString();
                    }

                    return true;


                }
            }
            catch(Exception ex)
            {

            }
            return res;
        }



        public void setCustomerServiceWechat()
        {
            try
            {
                Hashtable htWechatMap = new Hashtable();
                StringBuilder sb = new StringBuilder();
                ArrayList arListAllLines = new ArrayList();
                logHelp.LogHelper.Instance.writeLog(" setCustomerServiceWechat count=" + FrameDecoderManager.Instance.htCustomerServiceRoomsUsers.Count.ToString());
                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htCustomerServiceRoomsUsers)
                {
                    arListAllLines.Add(de.Key.ToString());

                }
                logHelp.LogHelper.Instance.writeConfig(StoParams.Instance.allCustomerServiceTxtPath, arListAllLines);

            }
            catch (Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog(" setDwawUserFilterWechat ex" + ex.ToString());
            }
        }



        public void setDwawUserFilterWechat()
        {
            try
            {
                Hashtable htWechatMap = new Hashtable();
                StringBuilder sb = new StringBuilder();
                ArrayList arListAllLines = new ArrayList();
                logHelp.LogHelper.Instance.writeLog(" htDrawingRoomsUsers count="+ FrameDecoderManager.Instance.htDrawingRoomsUsers.Count.ToString());
                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htDrawingRoomsUsers)
                {
                    string roomid = de.Key.ToString();
                    ArrayList arListFilter = (ArrayList)de.Value;
                    sb.AppendLine("roomid:" + roomid);
                    arListAllLines.Add("roomid:" + roomid);
                    foreach (string line in arListFilter)
                    {
                        sb.AppendLine(line);
                        arListAllLines.Add(line);
                    }

                }
                logHelp.LogHelper.Instance.writeConfig(StoParams.Instance.allDrawWechatTxtPath, arListAllLines);

            }
            catch (Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog(" setDwawUserFilterWechat ex" + ex.ToString());
            }
        }



        public void setCodingUserFilterWechat()
        {
            try
            {
                Hashtable htWechatMap = new Hashtable();
                StringBuilder sb = new StringBuilder();
                ArrayList arListAllLines = new ArrayList();
                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htCodingRoomsUsers)
                {
                    string roomid = de.Key.ToString();
                    ArrayList arListFilter = (ArrayList)de.Value;
                    sb.AppendLine("roomid:" + roomid);
                    arListAllLines.Add("roomid:" + roomid);
                    foreach (string line in arListFilter)
                    {
                        sb.AppendLine(line);
                        arListAllLines.Add(line);
                    }

                }
                logHelp.LogHelper.Instance.writeConfig(StoParams.Instance.allCodingWechatTxtPath, arListAllLines);

            }
            catch (Exception ex)
            {

            }
        }



        public void setUserFilterWechat()
        {
            try
            {
                Hashtable htWechatMap = new Hashtable();
                StringBuilder sb = new StringBuilder();
                ArrayList arListAllLines = new ArrayList();
                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htAllRoomsFilters)
                {
                    string roomid = de.Key.ToString();
                    ArrayList arListFilter = (ArrayList)de.Value;
                    sb.AppendLine("roomid:" + roomid);
                    arListAllLines.Add("roomid:" + roomid);
                    foreach (string line in arListFilter)
                    {
                        sb.AppendLine(line);
                        arListAllLines.Add(line);
                    }

                }
                logHelp.LogHelper.Instance.writeConfig(StoParams.Instance.allFilterWechatTxtPath, arListAllLines);               
       
            }
            catch (Exception ex)
            {

            }
        }

        public void sendHeartBeatToClient()
        {
            try
            {

            }
            catch(Exception ex)
            {

            }
        }


        public void handleFileMsgBeans(WechatMsgBean wechatMsgBean)
        {
            try
            {
                string fileName = wechatMsgBean.file;
                if(fileName.EndsWith("txt"))
                {
                    string fileType = "";
                    string singleFile = fileName.Substring(fileName.LastIndexOf('\\') + 1);
                    if(singleFile.Contains("催件")|| singleFile.Contains("催促"))
                    {
                        fileType = "催件";
                    }
                    if (singleFile.Contains("拦截") || singleFile.Contains("退回"))
                    {
                        fileType = "拦截";
                    }
                    if (singleFile.Contains("查重"))
                    {
                        fileType = "查重";
                    }
                    if (singleFile.Contains("揽收"))
                    {
                        fileType = "揽收";
                    }
                    if (singleFile.Contains("留言板"))
                    {
                        fileType = "留言板";
                    }
                    if (fileType=="")
                    {
                        return;
                    }
                    ArrayList arListAll = new ArrayList();
                    ArrayList arListTmp = new ArrayList();
                    Hashtable htFilter = new Hashtable();
                    foreach (string line in File.ReadLines(fileName, EncodingType.GetType(fileName)))
                    {
                        if (line.Length > 2)
                        {
                            if(htFilter.ContainsKey(line.Trim()))
                            {
                                continue;
                            }
                            if(line.StartsWith("JT"))
                            {
                                arListTmp.Add(line.Trim());
                                htFilter[line.Trim()] = line.Trim();
                            }
                            if(arListTmp.Count>118)
                            {
                                arListAll.Add(arListTmp.Clone());
                                arListTmp.Clear();
                            }                            
                        }
                    }
                    if(arListTmp.Count>0)
                    {
                        arListAll.Add(arListTmp.Clone());
                    }
                    foreach(ArrayList arList in arListAll)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach(string strLine in arList)
                        {
                            sb.AppendLine(strLine);
                        }
                        sb.AppendLine(fileType);

                        string strContent = "";
                        string msg = "";
                        JObject jObj = new JObject();
                        jObj["ServiceName"] = "wechatMsg";
                        jObj["roomid"] = wechatMsgBean.roomid;
                        jObj["content"] = sb.ToString();
                        jObj["msgtime"] = wechatMsgBean.msgtime;
                        jObj["msgtype"] = wechatMsgBean.msgtype;
                        jObj["from"] = wechatMsgBean.from;
                        string strSendContend = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                        byte[] contentBytes = System.Text.Encoding.UTF8.GetBytes(strSendContend);
                        int length = contentBytes.Length;
                        byte[] arrLength = ToBytes((uint)length, 4);
                        byte[] newArr = arrLength.Concat(contentBytes).ToArray();
                        Program.weServer.sendContent(newArr, wechatMsgBean.roomid, sb.ToString());

                    }
                    



                }
                else if((fileName.EndsWith("xlsx")|| fileName.EndsWith("xls")) && !fileName.Contains("限发明细"))
                {
                    if(fileName.Contains("揽收"))
                    {
                        if(StoParams.Instance.canLanshou)
                        {
                            handleFileExcel(wechatMsgBean, fileName);
                        }
                        else
                        {
                            JObject jObj = new JObject();
                            jObj["ServiceName"] = "wechatMsg";
                            jObj["roomid"] = wechatMsgBean.roomid;
                            jObj["content"] = "兜底客服";
                            jObj["msgtime"] = wechatMsgBean.msgtime;
                            jObj["msgtype"] = wechatMsgBean.msgtype;
                            jObj["from"] = wechatMsgBean.from;
                            string strSendContend = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                            byte[] contentBytes = System.Text.Encoding.UTF8.GetBytes(strSendContend);
                            int length = contentBytes.Length;
                            byte[] arrLength = ToBytes((uint)length, 4);
                            byte[] newArr = arrLength.Concat(contentBytes).ToArray();
                            Program.weServer.sendContent(newArr, wechatMsgBean.roomid, "兜底客服");
                        }
                        
                    }
                    /*JObject jObj = new JObject();
                    jObj["ServiceName"] = "wechatMsg";
                    jObj["roomid"] = wechatMsgBean.roomid;
                    jObj["content"] = "兜底客服";
                    jObj["msgtime"] = wechatMsgBean.msgtime;
                    jObj["msgtype"] = wechatMsgBean.msgtype;
                    jObj["from"] = wechatMsgBean.from;
                    string strSendContend = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                    byte[] contentBytes = System.Text.Encoding.UTF8.GetBytes(strSendContend);
                    int length = contentBytes.Length;
                    byte[] arrLength = ToBytes((uint)length, 4);
                    byte[] newArr = arrLength.Concat(contentBytes).ToArray();
                    Program.weServer.sendContent(newArr, wechatMsgBean.roomid, "兜底客服");*/
                }
                else if ((fileName.EndsWith("xlsx") || fileName.EndsWith("xls")) && !fileName.Contains("限发明细"))
                {
                    if (fileName.Contains("中转"))
                    {
                        JObject jObj = new JObject();
                        jObj["ServiceName"] = "wechatMsg";
                        jObj["roomid"] = wechatMsgBean.roomid;
                        jObj["content"] = "兜底客服";
                        jObj["msgtime"] = wechatMsgBean.msgtime;
                        jObj["msgtype"] = wechatMsgBean.msgtype;
                        jObj["from"] = wechatMsgBean.from;
                        string strSendContend = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                        byte[] contentBytes = System.Text.Encoding.UTF8.GetBytes(strSendContend);
                        int length = contentBytes.Length;
                        byte[] arrLength = ToBytes((uint)length, 4);
                        byte[] newArr = arrLength.Concat(contentBytes).ToArray();
                        Program.weServer.sendContent(newArr, wechatMsgBean.roomid, "兜底客服");
                    }
                    /**/
                }

            }
            catch(Exception ex)
            {

            }
        }


        private  void processExcel(object message)
        {
            try
            {
                ArrayList arListAll = new ArrayList();
                WechatMsgBean wechatMsgBean = (WechatMsgBean)message;
                string path = wechatMsgBean.filePath;
                LogHelper.Instance.writeLog("读取excel path=" + path.ToString());

                Worksheet sheet1 = UtilityExcel.Instance.GetWorksheet(path, 0);
                int rowCount = sheet1.Cells.Rows.Count;
                int cellCount = sheet1.Cells.Columns.Count;
                LogHelper.Instance.writeLog("读取excel 完成：rowcount=" + rowCount.ToString() + " Columns count=" + cellCount.ToString());
                ArrayList arListTmp = new ArrayList();

                Row row1 = sheet1.Cells.Rows[1];
                int maxRowCount = sheet1.Cells.MaxColumn;
                int jtIndex = 0;
                for(int m=0;m< maxRowCount;m++)
                {
                    string val = row1[m].Value.ToString();
                    if (val.Trim().StartsWith("JT") && val.Trim().Length > 10 && val.Trim().Length <= 17)
                    {
                        jtIndex= m;
                        break;
                    }
                }

                for (int i = 1; i < rowCount; i++)
                {
                    Row row = sheet1.Cells.Rows[i];
                    if (row.IsBlank)
                    {
                        continue;
                    }
                    if (row[jtIndex].Value != null)
                    {
                        string val = row[jtIndex].Value.ToString();
                        if (val.Trim().StartsWith("JT") && val.Trim().Length > 10 && val.Trim().Length <= 17)
                        {
                            arListTmp.Add(val.Trim());
                        }
                        if (arListTmp.Count > 118)
                        {
                            arListAll.Add(arListTmp.Clone());
                            arListTmp.Clear();
                        }
                    }

                }

                if(arListTmp.Count>0)
                {
                    arListAll.Add(arListTmp.Clone());
                }

                string fileType = "揽收";
                foreach (ArrayList arList in arListAll)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (string strLine in arList)
                    {
                        sb.AppendLine(strLine);
                    }
                    sb.AppendLine(fileType);

                    string strContent = "";
                    string msg = "";
                    JObject jObj = new JObject();
                    jObj["ServiceName"] = "wechatMsg";
                    jObj["roomid"] = wechatMsgBean.roomid;
                    jObj["content"] = sb.ToString();
                    jObj["msgtime"] = wechatMsgBean.msgtime;
                    jObj["msgtype"] = wechatMsgBean.msgtype;
                    jObj["from"] = wechatMsgBean.from;
                    string strSendContend = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                    byte[] contentBytes = System.Text.Encoding.UTF8.GetBytes(strSendContend);
                    int length = contentBytes.Length;
                    byte[] arrLength = ToBytes((uint)length, 4);
                    byte[] newArr = arrLength.Concat(contentBytes).ToArray();
                    Program.weServer.sendContent(newArr, wechatMsgBean.roomid, sb.ToString());
                    System.Threading.Thread.Sleep(50);
                    LogHelper.Instance.writeLog("发送揽收任务 " + arList.Count.ToString());

                }
            }
            catch(Exception ex)
            {
                LogHelper.Instance.writeLog("读取excel ex " + ex.ToString());
            }
            


        }


        public void handleFileExcel(WechatMsgBean wechatMsgBean,string fileName)
        {

            int curRow = 1;
            try
            {
                wechatMsgBean.filePath = fileName;
                Thread thread = new Thread(new ParameterizedThreadStart(processExcel));
                thread.Start((object)wechatMsgBean);


               



            }
            catch (Exception ex)
            {
                LogHelper.Instance.writeLog("handleFileExcel：ex  " + ex.ToString() + " ：" );
            }

        }


        public byte[] ToBytes(uint num, int size)
        {
            Contract.Assume(size <= 4);
            return BitConverter.GetBytes(num).Take(size).Reverse().ToArray();
        }
        

        public bool isProblemParcel(ArrayList arListRoadMap,string pickName,out string parcelType)
        {
            parcelType="";
            bool res = false;
            try
            {
                for(int i=0;i< arListRoadMap.Count;i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    string scanSite = roadBean.scanNetworkName;
                    if(StoParams.Instance.register_site.Contains("茂名"))
                    {
                        if (roadBean.scanTypeName.Contains("问题件") && i > arListRoadMap.Count - 3)
                        {
                            //res = true; ;
                        }
                    }
                    

                    /*if (roadBean.scanTypeName.Contains("完结"))
                    {
                        if(!roadBean.waybillTrackingContent.Contains("超时未签收"))
                        {
                            parcelType = "完结";
                            res = true;
                        }
                        
                    }*/

                    if (roadBean.waybillTrackingContent.Contains("作废件"))
                    {
                        parcelType = "作废件";
                        res = true; ;
                    }
                }
                
            }
            catch(Exception ex)
            {

            }
            return res;
        }

        public bool isBeanEffieLateThanCurSiteTime(string curSiteTime,DateTime dtBeanEffi)
        {
            bool isLateThanCurSite = false;
            try
            {
                if(dtBeanEffi>Convert.ToDateTime(curSiteTime))
                {
                    isLateThanCurSite = true;
                }
            }
            catch(Exception ex)
            {

            }
            return isLateThanCurSite;
        }


        private bool isJTParcel(string line)
        {
            bool res = false;
            try
            {
                if(line.Trim().StartsWith("JT"))
                {
                    string leftStr = line.Trim().Replace("JT", "");
                    if(MathUtility.ImpIsNum(leftStr))
                    {
                        res = true;
                    }
                }
            }
            catch(Exception ex)
            {

            }
            return res;
        }

        public string removeOtherParcel(string content)
        {
            string res = content;
            try
            {
                string[] arr = content.Split('\n');
                ArrayList arListToDel = new ArrayList();
                if (arr.Length >= 2)
                {
                    bool isOtherParcel = false;
                    for(int i=0;i< arr.Length;i++)
                    {
                        if(i>0&&i < arr.Length-1)
                        {
                            string curLine = arr[i];
                            //if()
                        }
                    }

                }

            }
            catch (Exception ex)
            {

            }
            return res;
        }


        public string removeFirstLineTime(string content)
        {
            string res = content;
            try
            {
                string[] arr = content.Split('\n');
                ArrayList arListToDel = new ArrayList();
                if(arr.Length>=2)
                {
                    foreach(string strLine in arr)
                    {
                        if (strLine.Contains(":"))
                        {
                            string[] arrTime = strLine.Split(' ');
                            try
                            {
                                DateTime dt = Convert.ToDateTime(arrTime[arrTime.Length - 1]);
                                res = res.Replace(strLine, "");
                                res = res.TrimStart('\n');
                            }
                            catch(Exception ex2)
                            {

                            }
                            


                        }
                    }
                    
                }

            }
            catch(Exception ex)
            {

            }
            return res;
        }

        public string removeYTParcel(WechatMsgBean wechatBean)
        {
            string res = wechatBean.content;
            try
            {
                if(!isLanShouOrTransfer(wechatBean))
                {
                    return res;
                }
                string[] arr = res.Split('\n');
                ArrayList arListToDel = new ArrayList();
                //if (arr.Length >= 2)
                {
                    foreach (string strLine in arr)
                    {
                        string[] arrtmp = strLine.Split(' ');
                        foreach(string v in arrtmp)
                        {
                            if(v.StartsWith("YT"))
                            {
                                string val = v.Replace("YT", "").Trim();
                                if(val.Length==13&&MathUtility.ImpIsNum(val))
                                {
                                    res = res.Replace(v, "");
                                    res = res.Replace("  ", " ");
                                }
                            }
                        }
                    }

                }
                res = res.Trim().TrimStart('\n');

            }
            catch (Exception ex)
            {

            }
            return res.Trim();
        }

        public string removeQQPngLink(string content)
        {
            string res = content;
            try
            {
                if(content.Contains("[pic"))
                {
                    int startIndex = content.IndexOf("[pic");
                    int endIndex = content.IndexOf("[pic");
                    if(content.Contains("]"))
                    {
                        endIndex = content.LastIndexOf(']')+1;
                    }
                    string strSub = content.Substring(startIndex, endIndex- startIndex);
                    content = content.Replace(strSub, "");

                }
                res = content;

            }
            catch (Exception ex)
            {

            }
            return res;
        }


        public string removeHeader(string content)
        {
            string res = content;
            try
            {
                if(!content.Contains("JT"))
                {
                    return res;
                }
                string subFirst = content.Substring(0, content.IndexOf("JT"));
                if(subFirst.Length<8)
                {
                    if(!subFirst.Contains("拦截")&& !subFirst.Contains("退回")&& !subFirst.Contains("催") && !subFirst.Contains("揽"))
                    {
                        content = content.Replace(subFirst, "");
                    }
                }
                res = content;

            }
            catch (Exception ex)
            {

            }
            return res;
        }

        public string removeHeaderByReference(string content)
        {
            string res = content;
            try
            {
                if(content.EndsWith("------\n核实图库")|| content.EndsWith("------\n存图")|| content.EndsWith("------\n核实编码") || content.EndsWith("------\n做编码"))
                {
                    res = content.Substring(content.LastIndexOf('\n')+1);
                }


                

            }
            catch (Exception ex)
            {

            }
            return res;
        }



        /// <summary>
        /// 换单退回逻辑
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        public string changeHDTHParcel(string content)
        {
            content = content.Replace("新的单号", "新单号");

            string res = content;
            try
            {
                if (content.Contains("新单号"))
                {
                    int startIndex = content.IndexOf("新单号");
                    
                    string strSub = content.Substring(startIndex);
                    if(strSub.Contains("JT"))
                    {
                        strSub = strSub.Insert(strSub.IndexOf("JT") + 1, " ");
                    }

                    res = content.Substring(0, startIndex)+ strSub;
                }
               

            }
            catch (Exception ex)
            {

            }
            return res;
        }




        public bool isNeedResetNestStopNetID(RoadBean roadBean,bool isCui)
        {
            bool isNeedReset = true;
            try
            {
                if(roadBean.nextStopName==null|| roadBean.nextStopName=="")
                {
                    isNeedReset = false;
                    return isNeedReset;
                }
                if(!isCui)
                {
                    if (roadBean.scanNetworkName.Contains("转运") || roadBean.scanNetworkName.Contains("分拨"))
                    {
                        if (roadBean.nextStopName.Contains("转运") || roadBean.nextStopName.Contains("分拨"))
                        {
                            isNeedReset = false;
                        }
                        else
                        {
                            isNeedReset = true;
                        }

                    }
                }
                else
                {
                    if (roadBean.scanNetworkName.Contains("转运") || roadBean.scanNetworkName.Contains("分拨"))
                    {
                        if (roadBean.nextStopName.Contains("转运") || roadBean.nextStopName.Contains("分拨"))
                        {
                            isNeedReset = false;
                        }
                        else
                        {
                            isNeedReset = true;
                        }

                    }
                }
                

                if (roadBean.scanNetworkName.Contains("集散"))
                {
                    if (roadBean.nextStopName.Contains("转运") || roadBean.nextStopName.Contains("分拨"))
                    {
                        isNeedReset = false;
                    }
                    else
                    {
                        isNeedReset = true;
                    }

                }

                else if (roadBean.scanNetworkName.Contains("网点"))
                {
                    isNeedReset = false;
                }
            }
            catch(Exception ex)
            {

            }
            return isNeedReset;
        }


        

         public void getCustomerCommon(string waybillNo, CustomerBean customerBean)
        {
            try
            {
                customerBean.waybillNo = waybillNo;
                JObject jObj = new JObject();
                JArray jarry = new JArray();

                string strUrl = "https://jmsgw.jtexpress.com.cn/sqsthird/thirdService/waybill/commonWaybillListByWaybillNos?waybillNos="+ waybillNo;

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);                       
                string res = HttpClient.HttpUtil.Instance.QueryCommon(strUrl, postData, "GET", "integratedComprehensive");

                totalQueryCount++;
                if (res.Contains("data"))
                {
                    JObject jsonObj = (JObject)JsonConvert.DeserializeObject(res);
                    JArray dArr = (JArray)jsonObj["data"];
                    JObject dataArr = (JObject)dArr[0];
                    if (dataArr != null)
                    {
               
                        JToken receiverName = (JToken)dataArr["receiverName"];
                        JToken receiverMobilePhone = (JToken)dataArr["receiverMobilePhone"];
                        JToken receiverProvinceName = (JToken)dataArr["receiverProvinceName"];
                        JToken receiverCityName = (JToken)dataArr["receiverCityName"];
                        JToken receiverAreaName = (JToken)dataArr["receiverAreaName"];
                        JToken receiverDetailedAddress = (JToken)dataArr["receiverDetailedAddress"];
                        JToken terminalDispatchCode = (JToken)dataArr["terminalDispatchCode"];
                        if (receiverName != null)
                        {
                            customerBean.receiverName = receiverName.ToString();
                        }
                        if (receiverMobilePhone != null)
                        {
                            customerBean.receiverMobilePhone = receiverMobilePhone.ToString();
                        }
                        if (receiverProvinceName != null)
                        {
                            customerBean.receiverProvinceName = receiverProvinceName.ToString();
                        }
                        if (receiverCityName != null)
                        {
                            customerBean.receiverCityName = receiverCityName.ToString();
                        }
                        if (receiverAreaName != null)
                        {
                            customerBean.receiverAreaName = receiverAreaName.ToString();
                        }
                        if (receiverDetailedAddress != null)
                        {
                            customerBean.receiverDetailedAddress = receiverDetailedAddress.ToString();
                        }
                        if (terminalDispatchCode != null)
                        {
                            customerBean.terminalDispatchCode = terminalDispatchCode.ToString();
                        }

                    }


                }
            }
            catch (Exception ex)
            {

            }
        }





        public void getOrderDetail(string waybillNo, CustomerBean customerBean,string token)
        {
            try
            {
                customerBean.waybillNo = waybillNo;
                JObject jObjDetail = new JObject();
                jObjDetail["waybillNo"] = waybillNo;
                jObjDetail["countryId"] = "1";

                string strUrl = "https://jmsgw.jtexpress.com.cn/operatingplatform/order/getOrderDetail";
                if(StoParams.Instance.isRabbitWin)
                {
                    strUrl = "https://wdgw.jtexpress.com.cn/ops/wdbutler/order/getOrderDetail";
                }

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObjDetail);
                string res = HttpClient.HttpUtil.Instance.PostCommonByToken(strUrl, postData, "trackingExpress", token);
                totalQueryCount++;
                if (res.Contains("data"))
                {
                    JObject jsonObj = (JObject)JsonConvert.DeserializeObject(res);
                    JObject dataArr = (JObject)jsonObj["data"];
                    if (dataArr != null)
                    {
                        JObject detailsRecords = (JObject)dataArr["details"];
                        JToken receiverName = (JToken)detailsRecords["receiverName"];
                        JToken receiverMobilePhone = (JToken)detailsRecords["receiverMobilePhone"];
                        JToken receiverProvinceName = (JToken)detailsRecords["receiverProvinceName"];
                        JToken receiverCityName = (JToken)detailsRecords["receiverCityName"];
                        JToken receiverAreaName = (JToken)detailsRecords["receiverAreaName"];
                        JToken receiverDetailedAddress = (JToken)detailsRecords["receiverDetailedAddress"];
                        JToken terminalDispatchCode= (JToken)detailsRecords["terminalDispatchCode"];
                        JToken customerName = (JToken)detailsRecords["customerName"];
                        
                        if(customerName!=null)
                        {
                            customerBean.customerName = customerName.ToString();
                        }
                        if (receiverName!=null)
                        {
                            customerBean.receiverName = receiverName.ToString();
                        }
                        if (receiverMobilePhone != null)
                        {
                            customerBean.receiverMobilePhone = receiverMobilePhone.ToString();
                        }
                        if (receiverProvinceName != null)
                        {
                            customerBean.receiverProvinceName = receiverProvinceName.ToString();
                        }
                        if (receiverCityName != null)
                        {
                            customerBean.receiverCityName = receiverCityName.ToString();
                        }
                        if (receiverAreaName != null)
                        {
                            customerBean.receiverAreaName = receiverAreaName.ToString();
                        }
                        if (receiverDetailedAddress != null)
                        {
                            customerBean.receiverDetailedAddress = receiverDetailedAddress.ToString();
                        }
                        if(terminalDispatchCode!=null)
                        {
                            customerBean.terminalDispatchCode = terminalDispatchCode.ToString();
                        }

                    }


                }
            }
            catch(Exception ex)
            {

            }
        }

        public string getReturnReason(string strBarCode,string applyNetworkName)
        {
            string res = "";
            try
            {
                string httpRes = "";
                ArrayList arListAllGXTask = new ArrayList();
                ArrayList arListRoadMap = JTDelayHelper.Instance.getRoadMap(strBarCode, out httpRes, arListAllGXTask);
                foreach(RoadBean roadBean in arListRoadMap)
                {                    
                    if(roadBean.scanTypeName.Contains("问题件扫描")&& roadBean.scanNetworkName!= applyNetworkName)
                    {
                        string content = roadBean.waybillTrackingContent;
                        if(content.Contains("问题件原因"))
                        {
                            content = content.Substring(content.LastIndexOf("问题件原因") + 5);
                            content = content.Replace("【", "");
                            content = content.Replace("】", "");
                            content = content.Trim();
                            res = content;
                        }
                    }
                }
            }
            catch(Exception ex)
            {

            }
            return res;

        }


        public void getInterceptProblems(ArrayList arListAllParcels,Hashtable htCustomerMap,Hashtable htTodaySend, string registerID, string token)
        { 
            try
            {                          
                int totalCout = 0;
                int totalPage = 0;
                int problemStatus = 1;
                handleToContinueCurrentPage(htTodaySend,htCustomerMap, 1, out totalCout, out totalPage, problemStatus, registerID, token);
         
                for (int pageIndex = 2; pageIndex <= totalPage; pageIndex++)
                {                    
                    handleToContinueCurrentPage(htTodaySend, htCustomerMap, pageIndex, out totalCout, out totalPage, problemStatus, registerID, token);
                }

                totalCout = 0;
                totalPage = 0;
                problemStatus = 2;
                handleToContinueCurrentPage(htTodaySend, htCustomerMap, 1, out totalCout, out totalPage, problemStatus, registerID, token);

                for (int pageIndex = 2; pageIndex <= totalPage; pageIndex++)
                {
                    handleToContinueCurrentPage(htTodaySend, htCustomerMap, pageIndex, out totalCout, out totalPage, problemStatus, registerID, token);
                }

            }
            catch (Exception ex)
            {

            }
        }

        private void handleToContinueCurrentPage(Hashtable htTodaySend, Hashtable htCustomerMap,
            int pageIndex, out int totalCount, out int totalPage,int problemStatus, string registerID, string token)
        {
            totalCount = 0;
            totalPage = 0;
            try
            {
                string strUrl = "https://jmsgw.jtexpress.com.cn/operatingplatform/rebackTransferExpress/problemExpressPage";
                JObject jObj = new JObject();

                jObj["current"] = pageIndex;
                jObj["size"] = 100;
                jObj["applyTimeFrom"] = DateTime.Now.AddDays(0).ToString("yyyy-MM-dd") + " 00:00:00";
                jObj["applyTimeTo"] = DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59";       
             
                jObj["status"] = problemStatus;
                jObj["auditNetworkId"] = registerID;
                jObj["countryId"] = "1";

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string res = BarcodeDelay.HttpClient.HttpUtil.Instance.PostCommonByToken(strUrl, postData, "returnAndForwardMaintain", token);
                if (res.Contains("请求成功"))
                {
                    if (res.Contains("data"))
                    {
                        JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(res);
                        JObject obgData = (JObject)jsonObjRes["data"];
                        JToken totalPages = (JToken)obgData["pages"];
                        JToken total = (JToken)obgData["total"];
                        JArray records = (JArray)obgData["records"];
                        totalCount = Convert.ToInt32(total);
                        totalPage = Convert.ToInt32(totalPages);

                        foreach (JObject record in records)
                        {
                            JToken waybillNo = (JToken)record["waybillNo"];
                            if (waybillNo.ToString().StartsWith("B"))
                            {
                                continue;
                            }

                            JToken applyTime = (JToken)record["applyTime"];
                            JToken rebackTransferReason= (JToken)record["rebackTransferReason"];
                            JToken customerName= (JToken)record["customerName"];

                            JToken applyNetworkName = (JToken)record["applyNetworkName"];

                            if (htTodaySend.ContainsKey(waybillNo.ToString()))
                            {
                                continue;
                            }

                            if(applyTime!=null)
                            {
                                DateTime dtApply = Convert.ToDateTime(applyTime.ToString());
                                TimeSpan ts = System.DateTime.Now - dtApply;
                                if(ts.TotalMinutes>25)
                                {
                                    continue;
                                }
                            }
                            ParcelBean parcel = new ParcelBean();
                            parcel.wayBill = waybillNo.ToString();
                            parcel.customerName = customerName.ToString();
                            if(applyNetworkName!=null)
                            {
                                parcel.rebackTransferReason=getReturnReason(waybillNo.ToString(), applyNetworkName.ToString());
                            }
                            
                            if(!htCustomerMap.ContainsKey(parcel.customerName))
                            {
                                htCustomerMap[parcel.customerName] = new ArrayList();
                            }
                            ArrayList arListCustomer = htCustomerMap[parcel.customerName] as ArrayList;
                            arListCustomer.Add(parcel);
                        }

                    }

                    //QueryMessageRes.Invoke();
                }
                

            }
            catch (Exception ex)
            {

            }
        }

        public string getMsgTypeIyID(string msgID)
        {
            string res = "遗失";
            switch(msgID)
            {
                case "1":
                    res = "破损";
                    break;
                case "2":
                    res = "延误";
                    break;
                case "3":
                    res = "遗失";
                    break;
                case "4":
                    res = "其他";
                    break;
                case "5":
                    res = "退转";
                    break;
                case "6":
                    res = "漏录签入";
                    break;
            }
            return res;
        }

        public void getAssignNameAndLastScan(CustomerBean customerBean,ArrayList arListRoadMap,string token)
        {
            try
            {
                string lastScanState="";
                string lastScanTime = "";
                string lanshouSite = "";
                if(arListRoadMap.Count>=5)
                {
                    for(int i= arListRoadMap.Count-5;i< arListRoadMap.Count;i++)
                    {
                        RoadBean roadBean = (RoadBean)arListRoadMap[i];
                        StringBuilder sb = new StringBuilder();
                        sb.AppendLine(roadBean.scanTime + " " + roadBean.scanTypeName + " " + roadBean.waybillTrackingContent);
                        customerBean.arListLastRoadMap.Add(sb.ToString());
                    }
                    
                }
                foreach (RoadBean roadBean in arListRoadMap)
                {
                    if(roadBean.scanTypeName.Contains("揽收"))
                    {
                        lanshouSite = roadBean.scanNetworkName;
                    }

                    if(roadBean.scanNetworkName.Contains("网点")&& lanshouSite!= roadBean.scanNetworkName && (roadBean.scanTypeName.Contains("出仓")
                        || roadBean.scanTypeName.Contains("入库") || roadBean.scanTypeName.Contains("问题件") || roadBean.scanTypeName.Contains("退件")))
                    {     
                        if(roadBean.staffName!="")
                        {
                            if(customerBean.dispatchName=="")
                            {
                                customerBean.dispatchName = roadBean.staffName;
                            }
                            else
                            {
                                //if (roadBean.staffName.Length<= customerBean.dispatchName.Length)
                                {
                                    customerBean.dispatchName = roadBean.staffName;
                                }
                            }
                            
                        }
                        else
                        {
                            string staffName = getStaffName(roadBean.waybillTrackingContent);
                            if(staffName.Trim().Length>1)
                            {
                                customerBean.dispatchName = staffName.Trim();
                            }
                        }                   
                       
                        if(roadBean.wareHouseName!="")
                        {
                            customerBean.warehouseName = roadBean.wareHouseName;
                        }
                    }


                    /*if (roadBean.scanNetworkName!= lanshouSite&&
                        (roadBean.scanTypeName.Contains("到件")|| roadBean.scanTypeName.Contains("快件取出扫描")
                        || roadBean.scanTypeName.Contains("入库") || roadBean.scanTypeName.Contains("出仓") 
                        || roadBean.scanTypeName.Contains("发件")))*/
                    if (roadBean.scanNetworkName != lanshouSite &&
                    (!roadBean.scanTypeName.Contains("问题件扫描")&& !roadBean.scanTypeName.Contains("完结")))
                    {
                        lastScanState = roadBean.scanTypeName;
                        lastScanTime = roadBean.scanTime;
                    }
                    if(StoParams.Instance.register_site.Contains("永平")|| StoParams.Instance.register_site.Contains("均禾"))
                    {
                        if (roadBean.scanNetworkName != lanshouSite)
                        {
                            lastScanState = roadBean.scanTypeName;
                            lastScanTime = roadBean.scanTime;
                        }
                    }

                }
                customerBean.waybillStatus = lastScanState;
                customerBean.lastScanTime = lastScanTime;
            }
            catch(Exception ex)
            {

            }

        }


        public void getMsgList(string waybillNo, CustomerBean customerBean,string token)
        {
            try
            {
                customerBean.waybillNo = waybillNo;
                JObject jObjDetail = new JObject();
                jObjDetail["waybillNo"] = waybillNo;
                jObjDetail["countryId"] = "1";

                string strUrl = "https://jmsgw.jtexpress.com.cn/operatingplatform/messageBoard/list";
                if(StoParams.Instance.isRabbitWin)
                {
                    strUrl = "https://wdgw.jtexpress.com.cn/ops/wdbutler/messageBoard/list";
                }

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObjDetail);
                string res = HttpClient.HttpUtil.Instance.PostCommonByToken(strUrl, postData, "trackingExpress", token);
                ArrayList arListTime = new ArrayList();
                Hashtable htTimeReply = new Hashtable();
                totalQueryCount++;
                if (res.Contains("data"))
                {
                    JObject jsonObj = (JObject)JsonConvert.DeserializeObject(res);
                    JArray dataArr = (JArray)jsonObj["data"];
                    customerBean.leaveMsgCout= dataArr.Count;
                    for (int i=0;i< dataArr.Count;i++)
                    {
                        JObject curObj = (JObject)dataArr[i];
                        string id = curObj["id"].ToString();
                        string createTime = curObj["createTime"].ToString();
                        string replyContent = curObj["replyContent"].ToString();
                        string leaveMessageID= curObj["leaveMessageType"].ToString();
                        string leaveMsgType = getMsgTypeIyID(leaveMessageID);
                        customerBean.leaveMsgType = leaveMsgType;

                        arListTime.Add(createTime);
                        string addMsg = "";
                        if (!replyContent.ToString().Contains("****"))
                        {
                            addMsg = createTime + " " + leaveMsgType+" " +replyContent.ToString();
                           
                        }
                        else
                        {
                            string url = "https://jmsgw.jtexpress.com.cn/servicequality/leaveMessage/query/replyContent?id=" + id.ToString();
                            if(StoParams.Instance.isRabbitWin)
                            {
                                url = "https://wdgw.jtexpress.com.cn/servicequality/leaveMessage/query/replyContent?id=" + id.ToString();
                            }
                            JObject jObj = new JObject();
                            postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                            res = HttpClient.HttpUtil.Instance.QueryCommon(url, postData, "GET", "commentsNew");
                            //DateTime dtNow = System.DateTime.Now;
                            int sjPages = 0;
                            int totalRequest = 0;
                            if (res.Contains("请求成功"))
                            {
                                if (res.Contains("data"))
                                {
                                    JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(res);
                                    JObject cruObjData = (JObject)jsonObjRes["data"];

                                    JToken replyContentToken = (JToken)cruObjData["replyContent"];
                                    string curReply = replyContentToken.ToString();
                                    //if (!curReply.ToString().Contains("****"))
                                    {
                                        addMsg = createTime + " " + leaveMsgType + " " + curReply.ToString();
                                    }

                                }

                                //QueryMessageRes.Invoke();
                            }

                        }

                        if(addMsg.Length>2)
                        {
                            htTimeReply[createTime] = addMsg;
                            customerBean.arListReplyContent.Add(addMsg);
                        }                      

                    }

                }
                if(arListTime.Count>0)
                {
                    arListTime.Sort();
                    arListTime.Reverse();
                    customerBean.arListReplyContent.Clear();
                    foreach(string strTime in arListTime)
                    {
                        if(htTimeReply.ContainsKey(strTime))
                        {
                            string addMsg = htTimeReply[strTime] as string;
                            customerBean.arListReplyContent.Add(addMsg);
                        }
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }


        public string getCustomerInfo(CustomerBean customerBean)
        {
            string res = "";
            try
            {
                string lastReply = "";
                if(customerBean.arListReplyContent.Count>0)
                {
                    lastReply = customerBean.arListReplyContent[0].ToString();
                    if(lastReply.Contains("-")&& lastReply.Contains(":"))
                    {
                        lastReply = lastReply.Substring(lastReply.IndexOf(' ', 13));
                        lastReply = lastReply.Trim();
                        lastReply = lastReply.Substring(lastReply.IndexOf(' ') + 1);
                    }
                }
                StringBuilder sb = new StringBuilder();
                sb.AppendLine(customerBean.waybillNo);
                sb.AppendLine("姓名："+ customerBean.receiverName);
                sb.AppendLine("电话：" + customerBean.receiverMobilePhone);
                sb.AppendLine("地址：" + customerBean.receiverProvinceName + customerBean.receiverCityName + customerBean.receiverAreaName + " " + customerBean.receiverDetailedAddress);

                //sb.AppendLine(customerBean.receiverName + " 电话：" + customerBean.receiverMobilePhone + " " + customerBean.receiverProvinceName + customerBean.receiverCityName + customerBean.receiverAreaName + " " + customerBean.receiverDetailedAddress);
                sb.AppendLine(getShourMonthAndDay(customerBean.lastScanTime)+" "+ customerBean.waybillStatus +" 派件员："+ customerBean.dispatchName);
                if(!StoParams.Instance.register_site.Contains("永平") && !StoParams.Instance.register_site.Contains("均禾"))
                {
                    sb.AppendLine(lastReply.Trim());
                }
                
                res = sb.ToString();
                //string customerInfo = customerBean.waybillNo+ "客户信息:" + customerBean.receiverName + " 电话：" + customerBean.receiverMobilePhone + " " + customerBean.receiverProvinceName + customerBean.receiverCityName + customerBean.receiverAreaName + " " + customerBean.receiverDetailedAddress;

            }
            catch (Exception ex)
            {

            }
            return res;
        }


        public void addCustomerInfoReply(CustomerBean customerBean)
        {
           
            try
            {
               
                if (customerBean.arListReplyContent.Count >5)
                {
                    return;
                }
                else
                {
                    int addCount = 5 - customerBean.arListReplyContent.Count;
                    for(int i=0;i< addCount;i++)
                    {
                        customerBean.arListReplyContent.Add("");
                    }
                }
                
                //string customerInfo = customerBean.waybillNo+ "客户信息:" + customerBean.receiverName + " 电话：" + customerBean.receiverMobilePhone + " " + customerBean.receiverProvinceName + customerBean.receiverCityName + customerBean.receiverAreaName + " " + customerBean.receiverDetailedAddress;

            }
            catch (Exception ex)
            {

            }
           
        }


        public string getShourMonthAndDay(string scanTime)
        {
            string res = scanTime;
            try
            {
                res = res.Substring(res.IndexOf('-') + 1);
                res = res.Substring(0, res.IndexOf(' '));
            }
            catch(Exception ex)
            {

            }
            return res;
           
        }

        private void handleOverTimeProjectWorkOrder(string regSiteID, Hashtable htOverTimeProjectWorder,
            int pageIndex, out int totalCount, out int totalPage,string token,WorkOrdrBean workOrderBean)
        {
            totalCount = 0;
            totalPage = 0;
            try
            {
                JObject jObjDetail = new JObject();
                jObjDetail["current"] = pageIndex;
                jObjDetail["size"] = 100;
                jObjDetail["acceptNetworkId"] = Convert.ToInt64(regSiteID);
                jObjDetail["queryType"] = 1;      


                jObjDetail["startTime"] = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
                jObjDetail["endTime"] = DateTime.Now.ToString("yyyy-MM-dd") + " " + "23:59:59";
                jObjDetail["countryId"] = "1";

                JArray workStatus = new JArray();
                workStatus.Add(0);
                workStatus.Add(1);
                workStatus.Add(2);

                jObjDetail["workOrderStatusList"] = workStatus;
                string strUrl = "https://jmsgw.jtexpress.com.cn/sqsprojectorder/projectWorkOrder/page";
                if (StoParams.Instance.isRabbitWin)
                {
                    strUrl = "https://wdgw.jtexpress.com.cn/sqsprojectorder/projectWorkOrder/page";
                }
                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObjDetail);
                string res = HttpClient.HttpUtil.Instance.PostCommonByToken(strUrl, postData, "projectWorkOrderManage", token);
                totalQueryCount++;
                if (res.Contains("data"))
                {
                    JObject jsonObj = (JObject)JsonConvert.DeserializeObject(res);
                    JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(res);
                    if (jsonObjRes != null)
                    {
                        JObject obgData = (JObject)jsonObjRes["data"];
                        JToken totalPages = (JToken)obgData["pages"];
                        JToken total = (JToken)obgData["total"];
                        JArray records = (JArray)obgData["records"];
                        totalCount = Convert.ToInt32(total);
                        totalPage = Convert.ToInt32(totalPages);
                        foreach (JObject record in records)
                        {
                            JToken workOrderNo = record["workOrderNo"];
                            JToken createTime = record["createTime"];
                            JToken workOrderChannelDesc = record["workOrderChannelDesc"];
                            JToken waybillNo = record["waybillNo"];
                            if (waybillNo != null)
                            {
                                workOrderNo = waybillNo;
                            }

                            TimeSpan ts = System.DateTime.Now - Convert.ToDateTime(createTime);
                            if (workOrderBean.platOverTimeHour2 == 0)
                            {
                                workOrderBean.platOverTimeHour2 = workOrderBean.platOverTimeHour1;
                            }

                            if (ts.TotalHours <= workOrderBean.platOverTimeHour2 && ts.TotalHours >= workOrderBean.platOverTimeHour1)
                            {
                                if (FrameDecoderManager.Instance.htOverTime15HourSiteOrderHandled.ContainsKey(workOrderNo.ToString()))
                                {
                                    continue;
                                }
                                else
                                {
                                    WorkOrder workOder = new WorkOrder();
                                    workOder.orderNo = workOrderNo.ToString();
                                    workOder.createTime = createTime.ToString();
                                    workOder.belongSite = workOrderBean.siteName;
                                    if (workOrderChannelDesc != null)
                                    {
                                        workOder.orderSource = workOrderChannelDesc.ToString();
                                    }

                                    int intHour = (int)(ts.TotalHours);
                                    workOder.workOrderTime = intHour.ToString() + "小时";

                                    FrameDecoderManager.Instance.htOverTime15HourSiteOrderHandled[workOrderNo.ToString()] = workOrderNo.ToString();
                                    htOverTimeProjectWorder[workOrderNo.ToString()] = workOder;
                                }
                            }

                            if(workOrderBean.platOverTimeHour2== workOrderBean.platOverTimeHour1)
                            {
                                continue;
                            }
                            if (ts.TotalHours >= workOrderBean.platOverTimeHour2 && ts.TotalHours <= 22)
                            {
                                if (FrameDecoderManager.Instance.htOverTime20HourSiteOrderHandled.ContainsKey(workOrderNo.ToString()))
                                {
                                    continue;
                                }
                                else
                                {
                                    WorkOrder workOder = new WorkOrder();
                                    workOder.orderNo = workOrderNo.ToString();
                                    workOder.createTime = createTime.ToString();
                                    workOder.belongSite = workOrderBean.siteName;
                                    if (workOrderChannelDesc != null)
                                    {
                                        workOder.orderSource = workOrderChannelDesc.ToString();
                                    }
                                    int intHour = (int)(ts.TotalHours);
                                    workOder.workOrderTime = intHour.ToString() + "小时";
                                    FrameDecoderManager.Instance.htOverTime20HourSiteOrderHandled[workOrderNo.ToString()] = workOrderNo.ToString();
                                    htOverTimeProjectWorder[workOrderNo.ToString()] = workOder;
                                }
                            }


                        }



                    }


                }



            }
            catch (Exception ex)
            {

            }
        }

        private void handleProjectWorkOrder(string regSiteID, Hashtable htProjectWorder, 
            int pageIndex, out int totalCount, out int totalPage,string token, WorkOrdrBean workOrderBean)
        {
            totalCount = 0;
            totalPage = 0;
            try
            {
                JObject jObjDetail = new JObject();
                jObjDetail["current"] = pageIndex;
                jObjDetail["size"] = 100;
                jObjDetail["acceptNetworkId"] = Convert.ToInt64(regSiteID);
                jObjDetail["queryType"] = 1;

                if (workOrderBean.platMinute > 0)
                {
                    jObjDetail["responseState"] = 1;
                }
                    
                

                jObjDetail["startTime"] = DateTime.Now.ToString("yyyy-MM-dd") + " " + "00:00:00";
                jObjDetail["endTime"] = DateTime.Now.ToString("yyyy-MM-dd") + " " + "23:59:59";
                jObjDetail["countryId"] = "1";
                string strUrl = "https://jmsgw.jtexpress.com.cn/sqsprojectorder/projectWorkOrder/page";

                if(StoParams.Instance.isRabbitWin)
                {
                    strUrl = "https://wdgw.jtexpress.com.cn/sqsprojectorder/projectWorkOrder/page";
                }

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObjDetail);
                string res = HttpClient.HttpUtil.Instance.PostCommonByToken(strUrl, postData, "projectWorkOrderManage", token);
                totalQueryCount++;
                if (res.Contains("请先在客服类型配置里配置当前用户的管理类型"))
                {
                    LogHelper.Instance.writeLog("平台工单 请先在客服类型配置里配置当前用户的管理类型 网点名称：" + workOrderBean.siteName);
                    return;
                }
                if (res.Contains("data"))
                {
                    JObject jsonObj = (JObject)JsonConvert.DeserializeObject(res);
                    JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(res);
                    if (jsonObjRes != null)
                    {
                        JObject obgData = (JObject)jsonObjRes["data"];
                        JToken totalPages = (JToken)obgData["pages"];
                        JToken total = (JToken)obgData["total"];
                        JArray records = (JArray)obgData["records"];
                        totalCount = Convert.ToInt32(total);
                        totalPage = Convert.ToInt32(totalPages);
                        foreach (JObject record in records)
                        {
                            JToken workOrderNo = record["workOrderNo"];
                            JToken createTime = record["createTime"];
                            JToken workOrderChannelDesc= record["workOrderChannelDesc"];
                            JToken waybillNo = record["waybillNo"];
                            JToken workOrderStatus = record["workOrderStatus"];
                            if (workOrderBean.platMinute > 0)
                            {
                                if (workOrderStatus.ToString() != "0")
                                {
                                    continue;
                                }
                            }
                                
                            TimeSpan ts = System.DateTime.Now - Convert.ToDateTime(createTime);
                            int totalSeconds = 2 * 60;
                            if(waybillNo!=null)
                            {
                                workOrderNo = waybillNo;
                            }
                            if (workOrderBean.platMinute == 0)
                            {
                                if (ts.TotalSeconds < totalSeconds)
                                {
                                    if (FrameDecoderManager.Instance.htSiteOrderHandled.ContainsKey(workOrderNo.ToString()))
                                    {
                                        continue;
                                    }
                                    else
                                    {
                                        WorkOrder workOder = new WorkOrder();
                                        workOder.orderNo = workOrderNo.ToString();
                                        workOder.createTime = createTime.ToString();
                                        workOder.belongSite = workOrderBean.siteName;
                                        if(workOrderChannelDesc != null)
                                        {
                                            workOder.orderSource = workOrderChannelDesc.ToString();
                                        }
                                        //workOder.workOrderTime = String.Format("{0:F1}", ts.TotalMinutes.ToString()) + "分钟";
                                        int intTime = (int)ts.TotalMinutes;

                                        workOder.workOrderTime = intTime.ToString() + "分钟";


                                        FrameDecoderManager.Instance.htSiteOrderHandled[workOrderNo.ToString()] = workOrderNo.ToString();
                                        htProjectWorder[workOrderNo.ToString()] = workOder;
                                    }
                                }
                            }
                            else
                            {
                                if (ts.TotalSeconds < workOrderBean.platMinute*60)
                                {
                                    continue;
                                }
                                if (FrameDecoderManager.Instance.htSiteOrderHandled.ContainsKey(workOrderNo.ToString()))
                                {
                                    continue;
                                }
                                else
                                {
                                    WorkOrder workOder = new WorkOrder();
                                    workOder.orderNo = workOrderNo.ToString();
                                    workOder.createTime = createTime.ToString();
                                    workOder.belongSite = workOrderBean.siteName;
                                    if (workOrderChannelDesc != null)
                                    {
                                        workOder.orderSource = workOrderChannelDesc.ToString();
                                    }
                                    int intTime = (int)ts.TotalMinutes;
                                    workOder.workOrderTime = intTime.ToString() + "分钟";

                                    FrameDecoderManager.Instance.htSiteOrderHandled[workOrderNo.ToString()] = workOrderNo.ToString();
                                    htProjectWorder[workOrderNo.ToString()] = workOder;
                                }
                            }
                           


                        }



                    }


                }



            }
            catch (Exception ex)
            {

            }
        }



        private void handleOvertimeOrdinayWorkOrder(string regSiteID, Hashtable htOverTimeOrdinayWorder, 
            int pageIndex, out int totalCount, out int totalPage,string token, WorkOrdrBean workOrderBean)
        {
            totalCount = 0;
            totalPage = 0;
            try
            {
                JObject jObjDetail = new JObject();
                jObjDetail["current"] = pageIndex;
                jObjDetail["size"] = 100;
                jObjDetail["current"] = pageIndex;
                jObjDetail["size"] = 100;
                jObjDetail["acceptNetworkId"] = Convert.ToInt64(regSiteID);
                jObjDetail["timeType"] = 1;
                jObjDetail["registrationStartTime"] = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + " " + "00:00:00";
                jObjDetail["registrationEndTime"] = DateTime.Now.ToString("yyyy-MM-dd") + " " + "23:59:59";
                jObjDetail["registrationNetworkIds"] = new JArray();
                jObjDetail["countryId"] = "1";             
                jObjDetail["type"] = "1";
                JArray statusList = new JArray();
                statusList.Add(1);
                statusList.Add(2);
                jObjDetail["statusList"] = statusList;
                string strUrl = "https://jmsgw.jtexpress.com.cn/sqsworkorder/workOrder/page";
                if(StoParams.Instance.isRabbitWin)
                {
                    strUrl = "https://wdgw.jtexpress.com.cn/sqsworkorder/workOrder/page";
                }

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObjDetail);
                string res = HttpClient.HttpUtil.Instance.PostCommonByToken(strUrl, postData, "ordinaryOrder", token);
                totalQueryCount++;
                if (res.Contains("data"))
                {
                    JObject jsonObj = (JObject)JsonConvert.DeserializeObject(res);
                    JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(res);
                    if (jsonObjRes != null)
                    {
                        JObject obgData = (JObject)jsonObjRes["data"];
                        JToken totalPages = (JToken)obgData["pages"];
                        JToken total = (JToken)obgData["total"];
                        JArray records = (JArray)obgData["records"];
                        totalCount = Convert.ToInt32(total);
                        totalPage = Convert.ToInt32(totalPages);
                        foreach (JObject record in records)
                        {
                            JToken workOrderNo = record["workOrderNo"];
                            JToken signTime = record["createTime"];
                            JToken workOrderChannelDesc= record["workOrderChannelDesc"];
                            JToken waybillNo= record["waybillNo"];
                            TimeSpan ts = System.DateTime.Now - Convert.ToDateTime(signTime);

                            if(workOrderNo.ToString().Contains("2023091700040952"))
                            {
                                int a = 0;
                            }
                            if(waybillNo!=null)
                            {
                                workOrderNo = waybillNo;
                            }


                            if(workOrderBean.ordinayOverTimeHour2==0)
                            {
                                workOrderBean.ordinayOverTimeHour2 = workOrderBean.ordinayOverTimeHour1;
                            }
                            if (ts.TotalHours <= workOrderBean.ordinayOverTimeHour2 && ts.TotalHours>= workOrderBean.ordinayOverTimeHour1)
                            {
                                if (FrameDecoderManager.Instance.htOverTime15HourSiteOrderHandled.ContainsKey(workOrderNo.ToString()))
                                {
                                    continue;
                                }
                                else
                                {
                                    WorkOrder workOder = new WorkOrder();
                                    workOder.orderNo = workOrderNo.ToString();
                                    workOder.createTime = signTime.ToString();
                                    workOder.belongSite = workOrderBean.siteName;
                                    if (workOrderChannelDesc != null)
                                    {
                                        workOder.orderSource = workOrderChannelDesc.ToString();
                                    }

                                    int intHour = (int)(ts.TotalHours);

                                    workOder.workOrderTime = intHour.ToString() + "小时";

                                    FrameDecoderManager.Instance.htOverTime15HourSiteOrderHandled[workOrderNo.ToString()] = workOrderNo.ToString();
                                    htOverTimeOrdinayWorder[workOrderNo.ToString()] = workOder;
                                }
                            }

                            if(workOrderBean.ordinayOverTimeHour2 == workOrderBean.ordinayOverTimeHour1)
                            {
                                continue;
                            }
                            if (ts.TotalHours >= workOrderBean.ordinayOverTimeHour2 && ts.TotalHours <=22)
                            {
                                if (FrameDecoderManager.Instance.htOverTime20HourSiteOrderHandled.ContainsKey(workOrderNo.ToString()))
                                {
                                    continue;
                                }
                                else
                                {
                                    WorkOrder workOder = new WorkOrder();
                                    workOder.orderNo = workOrderNo.ToString();
                                    workOder.createTime = signTime.ToString();
                                    workOder.belongSite = workOrderBean.siteName;
                                    if (workOrderChannelDesc != null)
                                    {
                                        workOder.orderSource = workOrderChannelDesc.ToString();
                                    }

                                    int intHour = (int)(ts.TotalHours);
                                    workOder.workOrderTime = intHour.ToString() + "小时";
                                    FrameDecoderManager.Instance.htOverTime20HourSiteOrderHandled[workOrderNo.ToString()] = workOrderNo.ToString();
                                    htOverTimeOrdinayWorder[workOrderNo.ToString()] = workOder;
                                }
                            }


                        }



                    }


                }



            }
            catch (Exception ex)
            {

            }
        }


        private void handleOrdinayWorkOrder(string regSiteID, Hashtable htOrdinayWorder,
            int pageIndex,out int  totalCount,out int totalPage,string token, WorkOrdrBean workOrderBean)
        {
            totalCount = 0;
            totalPage = 0;
            try
            {
                JObject jObjDetail = new JObject();
                jObjDetail["current"] = pageIndex;
                jObjDetail["size"] = 100;
                jObjDetail["acceptNetworkId"] = Convert.ToInt64(regSiteID);
                jObjDetail["timeType"] = 1;
                jObjDetail["registrationStartTime"] = DateTime.Now.ToString("yyyy-MM-dd") + " " + "00:00:00";
                jObjDetail["registrationEndTime"] = DateTime.Now.ToString("yyyy-MM-dd") + " " + "23:59:59";
                jObjDetail["registrationNetworkIds"] = new JArray();
                jObjDetail["countryId"] = "1";
                if(workOrderBean.ordinayMinute>0)
                {
                    jObjDetail["responseState"] = 3; 
                }

                jObjDetail["type"] = "1";
                string strUrl = "https://jmsgw.jtexpress.com.cn/sqsworkorder/workOrder/page";
                if (StoParams.Instance.isRabbitWin)
                {
                    strUrl = "https://wdgw.jtexpress.com.cn/sqsworkorder/workOrder/page";
                }

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObjDetail);
                string res = HttpClient.HttpUtil.Instance.PostCommonByToken(strUrl, postData, "ordinaryOrder", token);
                totalQueryCount++;
                if(res.Contains("请先在客服类型配置里配置当前用户的管理类型"))
                {
                    LogHelper.Instance.writeLog("普通工单 请先在客服类型配置里配置当前用户的管理类型 网点名称："+ workOrderBean.siteName+" token="+ token);
                    return;
                }
                if (res.Contains("data"))
                {
                    JObject jsonObj = (JObject)JsonConvert.DeserializeObject(res);
                    JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(res);
                    if (jsonObjRes != null)
                    {                                             
                        JObject obgData = (JObject)jsonObjRes["data"];
                        JToken totalPages = (JToken)obgData["pages"];
                        JToken total = (JToken)obgData["total"];
                        JArray records = (JArray)obgData["records"];
                        totalCount = Convert.ToInt32(total);
                        totalPage = Convert.ToInt32(totalPages);
                        foreach (JObject record in records)
                        {
                            JToken workOrderNo = record["workOrderNo"];
                            JToken createTime = record["createTime"];
                            JToken workOrderChannelDesc = record["workOrderChannelDesc"];
                            JToken workOrderStatus = record["workOrderStatus"];
                            JToken waybillNo = record["waybillNo"];
                            if(workOrderNo.ToString().Contains("2023091800004091"))
                            {
                                int a = 0;
                            }
                            if(waybillNo!=null)
                            {
                                workOrderNo = waybillNo;
                            }
                            if (workOrderBean.ordinayMinute > 0)
                            {
                                if (workOrderStatus.ToString() != "0")
                                {
                                    continue;
                                }
                            }
                                
                            

                            TimeSpan ts = System.DateTime.Now - Convert.ToDateTime(createTime);
                            int totalSeconds = 2 * 60;

                            if(workOrderBean.ordinayMinute==0)
                            {
                                if (ts.TotalSeconds < totalSeconds)
                                {
                                    if (FrameDecoderManager.Instance.htSiteOrderHandled.ContainsKey(workOrderNo.ToString()))
                                    {
                                        continue;
                                    }
                                    else
                                    {
                                        WorkOrder workOder = new WorkOrder();
                                        workOder.orderNo = workOrderNo.ToString();
                                        workOder.createTime = createTime.ToString();

                                        workOder.belongSite = workOrderBean.siteName;
                                        if (workOrderChannelDesc != null)
                                        {
                                            workOder.orderSource = workOrderChannelDesc.ToString();
                                        }
                                        int intTime = (int)ts.TotalMinutes;

                                        workOder.workOrderTime = intTime.ToString() + "分钟";
                                        FrameDecoderManager.Instance.htSiteOrderHandled[workOrderNo.ToString()] = workOrderNo.ToString();
                                        htOrdinayWorder[workOrderNo.ToString()] = workOder;
                                    }
                                }
                            }
                            if(workOrderBean.ordinayMinute>0)
                            {
                                if (ts.TotalSeconds < workOrderBean.ordinayMinute * 60)
                                {
                                    continue;
                                }

                                if (FrameDecoderManager.Instance.htSiteOrderHandled.ContainsKey(workOrderNo.ToString()))
                                {
                                    continue;
                                }
                                else
                                {
                                    WorkOrder workOder = new WorkOrder();
                                    workOder.orderNo = workOrderNo.ToString();
                                    workOder.createTime = createTime.ToString();
                                    workOder.belongSite = workOrderBean.siteName;
                                    if (workOrderChannelDesc != null)
                                    {
                                        workOder.orderSource = workOrderChannelDesc.ToString();
                                    }

                                    int intTime = (int)ts.TotalMinutes;

                                    workOder.workOrderTime = intTime.ToString() + "分钟";

                                    //workOder.workOrderTime = String.Format("{0:F1}", ts.TotalMinutes.ToString()) + "分钟";
                                    FrameDecoderManager.Instance.htSiteOrderHandled[workOrderNo.ToString()] = workOrderNo.ToString();
                                    htOrdinayWorder[workOrderNo.ToString()] = workOder;
                                }

                            }
                            


                        }



                    }


                }



            }
            catch(Exception ex)
            {

            }
        }

        private void handleOverTimeDispatchWorkOrder(string regSiteID, Hashtable htOverTimeDispatchWorder,
           int pageIndex, out int totalCount, out int totalPage, string token,WorkOrdrBean workOrdrBean)
        {
            totalCount = 0;
            totalPage = 0;
            string startTime = DateTime.Now.ToString("yyyy-MM-dd") + " " + "00:00:00";
            string endTime = DateTime.Now.ToString("yyyy-MM-dd") + " " + "23:59:59";
            try
            {


                string res = HttpClient.HttpUtil.Instance.postByRestSharpFromData(pageIndex, 100, startTime, endTime, token);
                totalQueryCount++;
                if (res.Contains("data"))
                {
                    JObject jsonObj = (JObject)JsonConvert.DeserializeObject(res);
                    JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(res);
                    if (jsonObjRes != null)
                    {
                        JObject obgData = (JObject)jsonObjRes["data"];
                        JToken totalPages = (JToken)obgData["pages"];
                        JToken total = (JToken)obgData["total"];
                        JArray records = (JArray)obgData["records"];
                        totalCount = Convert.ToInt32(total);
                        totalPage = Convert.ToInt32(totalPages);
                        foreach (JObject record in records)
                        {
                            JToken workOrderNo = record["waybillId"];
                            JToken createTime = record["inputTime"];
                            TimeSpan ts = System.DateTime.Now - Convert.ToDateTime(createTime);
                            if (workOrdrBean.dispatchOverTimeHour2 == 0)
                            {
                                workOrdrBean.dispatchOverTimeHour2 = workOrdrBean.dispatchOverTimeHour1;
                            }

                            if (ts.TotalHours <= workOrdrBean.dispatchOverTimeHour2 && ts.TotalHours >= workOrdrBean.dispatchOverTimeHour1)
                            {
                                if (FrameDecoderManager.Instance.htOverTime15HourSiteDispatchOrderHandled.ContainsKey(workOrderNo.ToString()))
                                {
                                    continue;
                                }
                                else
                                {
                                    WorkOrder workOder = new WorkOrder();
                                    workOder.orderNo = workOrderNo.ToString();
                                    workOder.createTime = createTime.ToString();
                                    FrameDecoderManager.Instance.htOverTime15HourSiteDispatchOrderHandled[workOrderNo.ToString()] = workOrderNo.ToString();
                                    htOverTimeDispatchWorder[workOrderNo.ToString()] = workOder;
                                }
                            }
                            if(workOrdrBean.dispatchOverTimeHour2== workOrdrBean.dispatchOverTimeHour1)
                            {
                                continue;
                            }

                            if (ts.TotalHours >= workOrdrBean.dispatchOverTimeHour2 && ts.TotalHours <= 22)
                            {
                                if (FrameDecoderManager.Instance.htOverTime20HourSiteDispatchOrderHandled.ContainsKey(workOrderNo.ToString()))
                                {
                                    continue;
                                }
                                else
                                {
                                    WorkOrder workOder = new WorkOrder();
                                    workOder.orderNo = workOrderNo.ToString();
                                    workOder.createTime = createTime.ToString();
                                    FrameDecoderManager.Instance.htOverTime20HourSiteDispatchOrderHandled[workOrderNo.ToString()] = workOrderNo.ToString();
                                    htOverTimeDispatchWorder[workOrderNo.ToString()] = workOder;
                                }
                            }


                        }



                    }


                }



            }
            catch (Exception ex)
            {

            }
        }

        private void handleDispatchWorkOrder(string regSiteID, Hashtable htProjectWorder,
            int pageIndex, out int totalCount, out int totalPage,string token, WorkOrdrBean workOrderBean)
        {
            totalCount = 0;
            totalPage = 0;
            string startTime = DateTime.Now.ToString("yyyy-MM-dd") + " " + "00:00:00";
            string endTime = DateTime.Now.ToString("yyyy-MM-dd") + " " + "23:59:59"; 
            try
            {
                

                string res = HttpClient.HttpUtil.Instance.postByRestSharpFromData(pageIndex, 100, startTime, endTime, token);
                totalQueryCount++;
                if (res.Contains("请先在客服类型配置里配置当前用户的管理类型"))
                {
                    LogHelper.Instance.writeLog("调度工单 请先在客服类型配置里配置当前用户的管理类型");
                    return;
                }
                if (res.Contains("data"))
                {
                    JObject jsonObj = (JObject)JsonConvert.DeserializeObject(res);
                    JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(res);
                    if (jsonObjRes != null)
                    {
                        JObject obgData = (JObject)jsonObjRes["data"];
                        JToken totalPages = (JToken)obgData["pages"];
                        JToken total = (JToken)obgData["total"];
                        JArray records = (JArray)obgData["records"];
                        totalCount = Convert.ToInt32(total);
                        totalPage = Convert.ToInt32(totalPages);
                        foreach (JObject record in records)
                        {
                            JToken workOrderNo = record["id"];
                            JToken createTime = record["inputTime"];
                            TimeSpan ts = System.DateTime.Now - Convert.ToDateTime(createTime);
                            int totalSeconds = 2 * 60;
                            if(workOrderBean.dispatchMinute==0)
                            {
                                if (ts.TotalSeconds < totalSeconds)
                                {
                                    if (FrameDecoderManager.Instance.htSiteOrderHandled.ContainsKey(workOrderNo.ToString()))
                                    {
                                        continue;
                                    }
                                    else
                                    {
                                        WorkOrder workOder = new WorkOrder();
                                        workOder.orderNo = workOrderNo.ToString();
                                        workOder.createTime = createTime.ToString();
                                        workOder.belongSite = workOrderBean.siteName;
                                        FrameDecoderManager.Instance.htSiteOrderHandled[workOrderNo.ToString()] = workOrderNo.ToString();
                                        htProjectWorder[workOrderNo.ToString()] = workOder;
                                    }
                                }
                            }
                            else
                            {
                                if(ts.TotalSeconds< workOrderBean.dispatchMinute*60)
                                {
                                    continue;
                                }
                                if (FrameDecoderManager.Instance.htSiteOrderHandled.ContainsKey(workOrderNo.ToString()))
                                {
                                    continue;
                                }
                                else
                                {
                                    WorkOrder workOder = new WorkOrder();
                                    workOder.orderNo = workOrderNo.ToString();
                                    workOder.createTime = createTime.ToString();
                                    workOder.belongSite = workOrderBean.siteName;
                                    FrameDecoderManager.Instance.htSiteOrderHandled[workOrderNo.ToString()] = workOrderNo.ToString();
                                    htProjectWorder[workOrderNo.ToString()] = workOder;
                                }
                            }
                            


                        }



                    }


                }



            }
            catch (Exception ex)
            {

            }
        }

        public void getOrdinayWorkOrder(string regSiteID, Hashtable htOrdinayWorder,string token,WorkOrdrBean workOrderBean)
        {
            try
            {

                int totalCout = 0;
                int totalPage = 0;
                handleOrdinayWorkOrder(regSiteID, htOrdinayWorder, 1, out totalCout, out totalPage, token, workOrderBean);
                //totalUnFinished = totalUnFinished + totalCout;       
                for (int pageIndex = 2; pageIndex <= totalPage; pageIndex++)
                {
                    handleOrdinayWorkOrder(regSiteID, htOrdinayWorder, pageIndex, out totalCout, out totalPage, token, workOrderBean);
                }


                
            }
            catch (Exception ex)
            {

            }
        }

        


        public void getOverTimeProjectWorkOrder(string regSiteID, Hashtable htOverTimeProjectWorder,string token,WorkOrdrBean workOrderBean)
        {
            try
            {

                int totalCout = 0;
                int totalPage = 0;
                handleOverTimeProjectWorkOrder(regSiteID, htOverTimeProjectWorder, 1, out totalCout, out totalPage, token,workOrderBean);
                //totalUnFinished = totalUnFinished + totalCout;       
                for (int pageIndex = 2; pageIndex <= totalPage; pageIndex++)
                {
                    handleOverTimeProjectWorkOrder(regSiteID, htOverTimeProjectWorder, pageIndex, out totalCout, out totalPage, token,workOrderBean);
                }



            }
            catch (Exception ex)
            {

            }
        }

        public void getOverTimeOrdinayWorkOrder(string regSiteID, Hashtable htOverTimeOrdinayWorder,string token,WorkOrdrBean workOrderBean)
        {
            try
            {

                int totalCout = 0;
                int totalPage = 0;
                handleOvertimeOrdinayWorkOrder(regSiteID, htOverTimeOrdinayWorder, 1, out totalCout, out totalPage, token, workOrderBean);
                //totalUnFinished = totalUnFinished + totalCout;       
                for (int pageIndex = 2; pageIndex <= totalPage; pageIndex++)
                {
                    handleOvertimeOrdinayWorkOrder(regSiteID, htOverTimeOrdinayWorder, pageIndex, out totalCout, out totalPage, token, workOrderBean);
                }



            }
            catch (Exception ex)
            {

            }
        }



        public void getProjectWorkOrder(string regSiteID, Hashtable htOrdinayWorder,string token,WorkOrdrBean workOrderBean)
        {
            try
            {

                int totalCout = 0;
                int totalPage = 0;
                this.handleProjectWorkOrder(regSiteID, htOrdinayWorder, 1, out totalCout, out totalPage, token, workOrderBean);
                //totalUnFinished = totalUnFinished + totalCout;       
                for (int pageIndex = 2; pageIndex <= totalPage; pageIndex++)
                {
                    this.handleProjectWorkOrder(regSiteID, htOrdinayWorder, pageIndex, out totalCout, out totalPage, token, workOrderBean);
                }



            }
            catch (Exception ex)
            {

            }
        }




        public void getDispatchWorkOrder(string regSiteID, Hashtable htDispatchWorder,string token, WorkOrdrBean workOrderBean)
        {
            try
            {

                int totalCout = 0;
                int totalPage = 0;
                this.handleDispatchWorkOrder(regSiteID, htDispatchWorder, 1, out totalCout, out totalPage, token, workOrderBean);
                //totalUnFinished = totalUnFinished + totalCout;       
                for (int pageIndex = 2; pageIndex <= totalPage; pageIndex++)
                {
                    this.handleDispatchWorkOrder(regSiteID, htDispatchWorder, pageIndex, out totalCout, out totalPage, token, workOrderBean);
                }



            }
            catch (Exception ex)
            {

            }
        }



        public void getOverTimeDispatchWorkOrder(string regSiteID, Hashtable htDispatchWorder, string token,WorkOrdrBean workOrderBean)
        {
            try
            {

                int totalCout = 0;
                int totalPage = 0;
                this.handleOverTimeDispatchWorkOrder(regSiteID, htDispatchWorder, 1, out totalCout, out totalPage, token,workOrderBean);
                //totalUnFinished = totalUnFinished + totalCout;       
                for (int pageIndex = 2; pageIndex <= totalPage; pageIndex++)
                {
                    this.handleOverTimeDispatchWorkOrder(regSiteID, htDispatchWorder, pageIndex, out totalCout, out totalPage, token,workOrderBean);
                }



            }
            catch (Exception ex)
            {

            }
        }


        public bool keepSiteAlive(string token,string siteName)
        {
            bool res = false;
            try
            {
                string strUrl = "https://jmsgw.jtexpress.com.cn/servicequality/problemPiece/getPageByName?current=1&size=10&queryLevel=3&name=" + siteName;
                if (StoParams.Instance.isRabbitWin)
                {
                    strUrl = "https://wdgw.jtexpress.com.cn/servicequality/problemPiece/getPageByName?current=1&size=1000&name=" + siteName;
                }
                JObject jObj = new JObject();
                JArray jarry = new JArray();

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string resMsg = BarcodeDelay.HttpClient.HttpUtil.Instance.QueryCommonByToekn(strUrl, postData, "GET", "batchProblem", token);
                if (resMsg.Contains("请求成功"))
                {
                    res = true;
                }
            }
            catch (Exception ex)
            {

            }
            return res;

        }



        public bool isLastRoadMapIsProblem(ArrayList arListRoadMap, SiteBean siteBean,out string curRoadStatus)
        {
            bool res = false;
            curRoadStatus = "";
            try
            {
               
                for (int i = arListRoadMap.Count - 1; i > 0; i--)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];

                    if (roadBean.scanNetworkName != StoParams.Instance.register_site)
                    {
                        if (roadBean.scanTypeName.Contains("问题件"))
                        {
                            res = true;
                            siteBean.siteCode = roadBean.scanNetworkCode;
                            siteBean.siteName = roadBean.scanNetworkName;
                            siteBean.siteId = roadBean.scanStieWorkID;

                            if (roadBean.scanTypeName == "问题件扫描")
                            {
                                curRoadStatus = roadBean.waybillTrackingContent;
                                curRoadStatus = curRoadStatus.Substring(curRoadStatus.LastIndexOf("问题件原因") + 5);
                                curRoadStatus = curRoadStatus.Replace("【", "");
                                curRoadStatus = curRoadStatus.Replace("】", "");
                                curRoadStatus = curRoadStatus.Trim();
                                curRoadStatus = "问题件:" + curRoadStatus;

                                if (curRoadStatus != "")
                                {
                                    string admsg = "核实处理";
                                    if (roadBean.waybillTrackingContent.Contains("签收"))
                                    {
                                        admsg = "核实签收";
                                    }
                                    curRoadStatus = curRoadStatus + "," + "已通知相关网点" + admsg+",并请贵司提供价值证明或者售后截图，我司安排追责";
                                    res = true;
                                }
                            }

                        }
                        else
                        {
                            res = false;
                        }
                        return res;
                    }
                }

            }
            catch (Exception ex)
            {

            }
            return res;

        }



        public string getStaffName(string waybillContent)
        {
            string res = "";
            try
            {
                if(waybillContent.Contains("已进行问题件扫描")|| waybillContent.Contains("退件") || waybillContent.Contains("转寄"))
                {
                    if(waybillContent.Contains("扫描员"))
                    {
                        res = waybillContent.Substring(waybillContent.LastIndexOf("扫描员") + 3);
                        res = res.Substring(1, res.IndexOf("】"));
                        res = res.Replace("【", "");
                        res = res.Replace("】", "");
                    }
                    else if(waybillContent.Contains("人员是"))
                    {
                        res = waybillContent.Substring(waybillContent.LastIndexOf("人员是") + 3);
                        res = res.Substring(1, res.IndexOf("】"));
                        res = res.Replace("【", "");
                        res = res.Replace("】", "");
                    }

                }
            }
            catch(Exception ex)
            {

            }
            return res;
        }


        public bool isOnWayBack(ArrayList arListRoadMap,string pickSite,out string backMsg)
        {
            backMsg = "";
            bool isBack = false;
            try
            {
                RoadBean roadBean = (RoadBean)arListRoadMap[arListRoadMap.Count - 1];

                RoadBean lastRoadBean = (RoadBean)arListRoadMap[arListRoadMap.Count - 1];

                if ((roadBean.scanTypeName.Contains("问题件扫描")|| roadBean.scanTypeName.Contains("拦截件登记"))
                    && roadBean.scanNetworkName== pickSite)
                {
                    isBack = false;
                    backMsg = "已登记过拦截";
                    /*TimeSpan ts= System.DateTime.Now - Convert.ToDateTime(roadBean.scanTime);
                    if(ts.TotalHours>48)
                    {
                        int totalDays = (int)ts.TotalDays;
                        backMsg = backMsg + ",超" + totalDays.ToString() + "天没退回";
                    }*/
                }
                else
                {
                    int interCeptIndex = 0;
                    for(int i=0;i< arListRoadMap.Count;i++)
                    {
                        roadBean = (RoadBean)arListRoadMap[i];
                        if ((roadBean.scanTypeName.Contains("问题件扫描") || roadBean.scanTypeName.Contains("拦截件登记"))
                     && roadBean.scanNetworkName == pickSite)
                        {
                            interCeptIndex = i;
                        }
                    }
                    string backRoadTime = "";
                    bool hasReturnMySite = false;
                    bool hasSiteDep = false;
                    for(int curIndex= interCeptIndex+1;curIndex< arListRoadMap.Count;curIndex++)
                    {
                        roadBean = (RoadBean)arListRoadMap[curIndex];
                        if(roadBean.scanNetworkName!= pickSite)
                        {
                            backRoadTime = roadBean.scanTime;
                        }
                        if(roadBean.nextStopName!=""&& roadBean.nextStopName== pickSite)
                        {
                            hasReturnMySite = true;
                        }
                        if(roadBean.scanNetworkName.Contains("网点")&& roadBean.scanNetworkName!=StoParams.Instance.register_site)
                        {
                            if(roadBean.scanTypeName.Contains("发件"))
                            {
                                hasSiteDep = true;
                            }
                        }
                    }
                    if(hasReturnMySite)
                    {
                        isBack = true;
                        backMsg = "已退回揽收站点";
                    }              
                    else
                    {
                        if(hasSiteDep)
                        {
                            isBack = true;
                            backMsg = "此件在退回途中";
                        }
                        
                    }


                }
            }
            catch(Exception ex)
            {

            }
            return isBack;
        }





        public string getLastValidStatus(ArrayList arListRoadMap)
        {

            string lastStatus = "";
            try
            {
                for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    if(roadBean.scanTypeName.Contains("出仓扫描"))
                    {
                        lastStatus = "派件";
                    }

                    if (roadBean.scanTypeName.Contains("入库扫描"))
                    {
                        lastStatus = "第三方";
                    }
                }

            }
            catch (Exception ex)
            {

            }
            return lastStatus;
        }



        public string getLastParCelStatus(ArrayList arListRoadMap)
        {

            string lastStatus = "";
            try
            {
                for(int i=arListRoadMap.Count-1;i>0; i--)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    if(roadBean.scanTypeName.Contains("退件")|| roadBean.scanTypeName.Contains("拦截件") || roadBean.scanTypeName.Contains("问题件") || roadBean.scanTypeName.Contains("完结"))
                    {
                        continue;
                    }
                    if(roadBean.scanNetworkName!=StoParams.Instance.register_site)
                    {
                        lastStatus = roadBean.scanTypeName;
                        break;
                    }
                   
                }
        

            }
            catch (Exception ex)
            {

            }
            return lastStatus;
        }




        public bool isValidQQMsg(string msg)
        {
            bool res = false;
            try
            {
                if(msg.Contains("JT"))
                {
                    res = true;
                    return res;
                }
                if(msg.Contains("设置留言微信")|| msg.Contains("注册网点") || msg.Contains("开启") || msg.Contains("屏蔽")
                    || msg.Contains("关闭") || msg.Contains("跟单") || msg.Contains("留言板") || msg.Contains("电联")
                    || msg.Contains("兜底客服") || msg.Contains("网点客服")||msg.Contains("loginTime"))
                {
                    res = true;
                }

            }
            catch(Exception ex)
            {

            }
            return res;
        }




        public string getOverTimeParcel(ArrayList arListRoadMap)
        {
            bool isBack = false;
            string res = "";
            try
            {
                string lanshouTime = "";
                for (int curIndex = 0; curIndex < arListRoadMap.Count; curIndex++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[curIndex];
                    if(roadBean.scanTypeName.Contains("揽收")|| roadBean.scanTypeName.Contains("入仓"))
                    {
                        lanshouTime = roadBean.scanTime;
                        break;
                    }
                    
                }
                TimeSpan ts = System.DateTime.Now - Convert.ToDateTime(lanshouTime);
                if(ts.TotalDays>=28&& ts.TotalDays <= 30)
                {
                    res = "以上订单已通知网点核实处理 此件即将超期  请务必提供收件人信息以及交易截图我司去追责 请及时提供 超期我司无法追责理赔 ";
                }
                else if(ts.TotalDays>30)
                {
                    res = "以上订单已通知网点核实处理 此件已过查件有效期 我这边跟进处理下 但是无法追责理赔";
                    if(StoParams.Instance.register_site.Contains("曹三")|| StoParams.Instance.register_site.Contains("菊城"))
                    {
                        res = "亲，此件超期反馈了哦，我司留言通知核实";
                    }
                }


            }
            catch (Exception ex)
            {

            }
            return res;
        }



        public bool isRoadSame(string fromCenter,string firstTaskNo,string sceondTaskNo)
        {
            bool res = false;
            try
            {

            }
            catch(Exception ex)
            {

            }
            return res;
        }


        public string getPlanArrivalTimeByTaskNo(string taskNo)
        {
            string res = "";
            try
            {
                string strUrl = "https://jmsgw.jtexpress.com.cn/operatingplatform/pod/getTaskInfo?taskCode=" + taskNo.ToString();
                if (StoParams.Instance.isRabbitWin)
                {
                    strUrl = "https://wdgw.jtexpress.com.cn/ops/wdbutler/pod/getTaskInfo?taskCode=" + taskNo.ToString();
                }
                JObject jObj = new JObject();
                JArray jarry = new JArray();
                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);

                //string postData = "{\"isAllPod\":1,\"keywordList\":[\"JT5036358713908\",\"JT5036397106300\"],\"trackingTypeEnum\":\"WAYBILL\",\"countryId\":\"1\"}";
                string response = HttpClient.HttpUtil.Instance.QueryCommon(strUrl, postData, "GET", "trackingExpress");

                if (response.Contains("data"))
                {

                    JObject jsonObj = (JObject)JsonConvert.DeserializeObject(response);
                    string resMsg = jsonObj["msg"].ToString();
                    JObject dataObj = (JObject)jsonObj["data"];
                    JToken plannedArrivalTime = dataObj["plannedArrivalTime"];
                    JToken actualArrivalTime = dataObj["actualArrivalTime"];

                    JToken shipmentName = dataObj["shipmentName"];
                    if (plannedArrivalTime != null && plannedArrivalTime.ToString().Length > 4)
                    {

                        res = plannedArrivalTime.ToString();
                        

                    }



                }
            }
            catch(Exception ex)
            {

            }
            return res;
        }


        public int getTotalReturnDelayDays(string scanOut,string scanNext)
        {
            int res = 0;
            try
            {
                string outDate = Convert.ToDateTime(scanOut).ToShortDateString();
                string next = Convert.ToDateTime(scanNext).ToShortDateString();
                TimeSpan ts = Convert.ToDateTime(next) - Convert.ToDateTime(outDate);
                if(ts.TotalDays>0)
                {
                    res = (int)ts.TotalDays;
                }

            }
            catch(Exception ex)
            {

            }
            return res;

        }



        public void initCustomerGroupEmployee()
        {
        
            int curRow = 1;
            try
            {
                string path = System.Environment.CurrentDirectory + "\\" + StoParams.Instance.EmployeeGroupSitePath;
                //string path = System.Environment.CurrentDirectory + "\\" + "极兔揽收11.1.xls";
                LogHelper.Instance.writeLog("初始化完成：path=" + path);

                Worksheet sheet1 = UtilityExcel.Instance.GetWorksheet(path, 0);
                int rowCount = sheet1.Cells.Rows.Count;
                int cellCount = sheet1.Cells.Columns.Count;






                LogHelper.Instance.writeLog("初始化完成：rowcount=" + rowCount.ToString());
                for (int i = 1; i < rowCount; i++)
                {
                    curRow = i;

                   
                    Row row = sheet1.Cells.Rows[i];
                    if (row.IsBlank)
                    {
                        continue;
                    }
                    




                    string customerName = "";
                    if(row[0].Value!=null)
                    {
                        customerName = row[0].Value.ToString();
                    }

                    string groupType = "";
                    if (row[1].Value != null)
                    {
                        groupType = row[1].Value.ToString();
                    }

                    string employee = "";
                    if (row[2].Value != null)
                    {
                        employee = row[2].Value.ToString();
                    }

                    string groupName = "";
                    if (row[3].Value != null)
                    {
                        groupName = row[3].Value.ToString();
                    }

               

        
                    CustomerAndDutyPerson cusPerson = new CustomerAndDutyPerson();
                    cusPerson.customerName = customerName.Trim();

                    cusPerson.groupType = groupType;
                    cusPerson.groupName = groupName;
                    cusPerson.employee = employee;
                    if(!StoParams.Instance.htCustomerAndDuty.ContainsKey(cusPerson.customerName))
                    {
                        StoParams.Instance.htCustomerAndDuty[cusPerson.customerName] = cusPerson;
                    }







                }
                LogHelper.Instance.writeLog("初始化完成：类型共有客户 " + StoParams.Instance.htCustomerAndDuty.Count.ToString());


                /*ArrayList arListReg = UtilityHelp.Instance.getTokenSiteName(path);
                if (arListReg.Count > 0)
                {
                    foreach (string strLine in arListReg)
                    {
                        if (strLine.Length > 3)
                        {
                            string newLine = strLine.Replace("：", ":");
                            string[] arr = newLine.Split(':');
                            if (arr.Length == 2)
                            {           
                                StoParams.Instance.htAllProblemTypeAck[arr[0]] = arr[1];
                            }                          





                        }

                    }
                }*/
                //mergeExcel();
            }
            catch (Exception ex)
            {
                LogHelper.Instance.writeLog("初始化完成：ex  " + ex.ToString() + " 行号：" + curRow.ToString());
            }

        }



        public void mergeExcel()
        {
            Hashtable ht = StoParams.Instance.htCustomerAndDuty;
            int curRow = 1;
            try
            {
                string path = System.Environment.CurrentDirectory + "\\" + "出港自动回复汇总_20231028175618.xls";

                LogHelper.Instance.writeLog("初始化完成：path=" + path);

                Worksheet sheet1 = UtilityExcel.Instance.GetWorksheet(path, 0);
                int rowCount = sheet1.Cells.Rows.Count;
                sheet1.Cells.InsertColumns(13, 3);

                LogHelper.Instance.writeLog("初始化完成：rowcount=" + rowCount.ToString());

                Workbook wb = new Workbook(FileFormatType.Xlsx);

                ArrayList arListStatic = new ArrayList();
                for (int i = 1; i < rowCount; i++)
                {
                    OutBoundProblemBean outBoundBean = new OutBoundProblemBean();
                    curRow = i;
                    Row row = sheet1.Cells.Rows[i];
                    
                    if (row.IsBlank)
                    {
                        continue;
                    }

                    string waybill = "";
                    if (row[0].Value != null)
                    {
                        waybill = row[0].Value.ToString();
                        outBoundBean.wayBill = waybill;
                    }

                  
                    if (row[1].Value != null)
                    {
                        outBoundBean.regSite = row[1].Value.ToString();
                    }

                    if (row[2].Value != null)
                    {
                        outBoundBean.firstTypeName = row[2].Value.ToString();
                    }

                    string problemName = "";
                    if (row[3].Value != null)
                    {
                        problemName = row[3].Value.ToString();
                        outBoundBean.secondTypeName = problemName;
                    }

                    if (row[4].Value != null)
                    {
                        outBoundBean.probleDescription = row[4].Value.ToString();
                        
                    }

                    if (row[6].Value != null)
                    {
                        outBoundBean.registrationNetworkName = row[6].Value.ToString();

                    }
                    if (row[7].Value != null)
                    {
                        outBoundBean.createTime = row[7].Value.ToString();

                    }
                    if (row[8].Value != null)
                    {
                        outBoundBean.customerCode = row[8].Value.ToString();

                    }
                    if (row[9].Value != null)
                    {
                        outBoundBean.customerName = row[9].Value.ToString();

                    }

                    if (row[12].Value != null)
                    {
                        outBoundBean.replyContent = row[12].Value.ToString();

                    }
                    

                    if(StoParams.Instance.htCustomerAndDuty.ContainsKey(outBoundBean.customerName))
                    {
                        CustomerAndDutyPerson curPerson = StoParams.Instance.htCustomerAndDuty[outBoundBean.customerName] as CustomerAndDutyPerson;

                        outBoundBean.groupType = curPerson.groupType;
                        outBoundBean.employee = curPerson.employee;
                        outBoundBean.groupName = curPerson.groupName;
                    }

                    arListStatic.Add(outBoundBean);









                }
                LogHelper.Instance.writeLog("初始化完成：类型共有 " + StoParams.Instance.htAllProblemTypeAck.Count.ToString());
                string add = "";
                UtilityExcel.Instance.GenExcelForOutBoundAckNew(arListStatic,System.Environment.CurrentDirectory , out add);


                /*ArrayList arListReg = UtilityHelp.Instance.getTokenSiteName(path);
                if (arListReg.Count > 0)
                {
                    foreach (string strLine in arListReg)
                    {
                        if (strLine.Length > 3)
                        {
                            string newLine = strLine.Replace("：", ":");
                            string[] arr = newLine.Split(':');
                            if (arr.Length == 2)
                            {           
                                StoParams.Instance.htAllProblemTypeAck[arr[0]] = arr[1];
                            }                          





                        }

                    }
                }*/

            }
            catch (Exception ex)
            {
                LogHelper.Instance.writeLog("初始化完成：ex  " + ex.ToString() + " 行号：" + curRow.ToString());
            }

        }



        public string GetMACAddress()
        {
            string macAddress = "";
            foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
            {
                if (nic.OperationalStatus == OperationalStatus.Up)
                {
                    macAddress = nic.GetPhysicalAddress().ToString();
                    break;
                }
            }
            return macAddress;
        }


        /// <summary>
        /// 获取最后的路由状态，已揽收，中转、出仓 ，入库，签收等
        /// </summary>
        /// <param name="customerBean"></param>
        /// <param name="arListRoadMap"></param>
        /// <param name="token"></param>
        public void getLastScanStatus(ArrayList arListRoadMap, string pickName, out string curStatus)
        {
            curStatus = "";
            try
            {
                
                if(arListRoadMap.Count==0)
                {
                    curStatus = "未揽收";
                    return;
                }
                string lastScanState = "";
                string lastScanTime = "";
                string lanshouSite = "";
                /*if (arListRoadMap.Count >= 5)
                {
                    for (int i = arListRoadMap.Count - 5; i < arListRoadMap.Count; i++)
                    {
                        RoadBean roadBean = (RoadBean)arListRoadMap[i];
                        StringBuilder sb = new StringBuilder();
                        sb.AppendLine(roadBean.scanTime + " " + roadBean.scanTypeName + " " + roadBean.waybillTrackingContent);
                        customerBean.arListLastRoadMap.Add(sb.ToString());
                    }

                }
                foreach (RoadBean roadBean in arListRoadMap)
                {
                    if (roadBean.scanTypeName.Contains("揽收"))
                    {
                        lanshouSite = roadBean.scanNetworkName;
                    }

                    if (roadBean.scanNetworkName.Contains("网点") && lanshouSite != roadBean.scanNetworkName && (roadBean.scanTypeName.Contains("出仓")
                        || roadBean.scanTypeName.Contains("入库") || roadBean.scanTypeName.Contains("问题件") || roadBean.scanTypeName.Contains("退件")))
                    {
                        if (roadBean.staffName != "")
                        {
                            if (customerBean.dispatchName == "")
                            {
                                customerBean.dispatchName = roadBean.staffName;
                            }
                            else
                            {
                                //if (roadBean.staffName.Length<= customerBean.dispatchName.Length)
                                {
                                    customerBean.dispatchName = roadBean.staffName;
                                }
                            }

                        }
                        else
                        {
                            string staffName = getStaffName(roadBean.waybillTrackingContent);
                            if (staffName.Trim().Length > 1)
                            {
                                customerBean.dispatchName = staffName.Trim();
                            }
                        }

                        if (roadBean.wareHouseName != "")
                        {
                            customerBean.warehouseName = roadBean.wareHouseName;
                        }
                    }



                    if (roadBean.scanNetworkName != lanshouSite &&
                    (!roadBean.scanTypeName.Contains("问题件扫描") && !roadBean.scanTypeName.Contains("完结")))
                    {
                        lastScanState = roadBean.scanTypeName;
                        lastScanTime = roadBean.scanTime;
                    }
                    if (StoParams.Instance.register_site.Contains("永平") || StoParams.Instance.register_site.Contains("均禾"))
                    {
                        if (roadBean.scanNetworkName != lanshouSite)
                        {
                            lastScanState = roadBean.scanTypeName;
                            lastScanTime = roadBean.scanTime;
                        }
                    }

                }
                customerBean.waybillStatus = lastScanState;
                customerBean.lastScanTime = lastScanTime;*/
            }
            catch (Exception ex)
            {

            }

        }



        public string removeAtUser(string content)
        {
            string res = content;
            try
            {
                if(content.Length<15)
                {
                    return res;
                }
                if(res.Contains("@"))
                {
                    string firstPart = res.Substring(0, res.IndexOf('@'));
                    string lastPart = res.Substring(res.IndexOf('@') + 1);
                    if(firstPart.Length> lastPart.Length)
                    {
                        res = firstPart;
                    }

                }

            }
            catch(Exception ex)
            {

            }
            return res;
        }


        public string getUserWechatCurrent(Hashtable htRoomCurrent,string roomiD,string userWechat)
        {
            string res = userWechat;
            try
            {
                if(userWechat.Contains("或"))
                {
                    string[] arr = userWechat.Split(new string[] { "或" }, StringSplitOptions.None);
                    if(!htRoomCurrent.ContainsKey(roomiD))
                    {
                        htRoomCurrent[roomiD] = arr[0];
                        res = arr[0];
                    }
                    else
                    {
                        int curIndex = 0;
                        for(int i=0;i< arr.Length;i++)
                        {
                            if(htRoomCurrent[roomiD].ToString()== arr[i])
                            {
                                curIndex = i + 1;
                                break;
                            }
                        }
                        if(curIndex == arr.Length)
                        {
                            curIndex = 0;
                        }
                        res = arr[curIndex];
                        htRoomCurrent[roomiD] = res;
                    }
                }

            }
            catch(Exception ex)
            {

            }
            return res;

        }


        public void getTaskBean(WechatMsgBean wechatBean,TaskBean taskBean)
        {
            try
            {

                if (isDrawingTask(wechatBean)&& isCodingTask(wechatBean))
                {
                    taskBean.taskType = "美工&编码";
                }
                else if (isDrawingTask(wechatBean))
                {
                    taskBean.taskType = "美工";
                }
                else if (isCodingTask(wechatBean))
                {
                    taskBean.taskType = "做编码";
                }
                else if (isChangeCodingTask(wechatBean))
                {
                    taskBean.taskType = "改编码";
                }

                else if (isCustomTask(wechatBean))
                {
                    taskBean.taskType = "客服";
                }

                else if (isLanshouTask(wechatBean, taskBean)&& isGenDanTask(wechatBean, taskBean))
                {
                    taskBean.taskType = "揽收&跟单";
                }
                else if (isLanshouTask(wechatBean, taskBean))
                {
                    taskBean.taskType = "揽收";
                }
                else if (isGenDanTask(wechatBean, taskBean))
                {
                    taskBean.taskType = "跟单";
                    if(StoParams.Instance.returnChange)
                    {
                        if(isInterCept(wechatBean.content))
                        {
                            taskBean.replyCustomer = false;
                            if(!isContainQuestion(wechatBean.content))
                            {
                                taskBean.isInterCept = true;
                                if (wechatBean.content.Contains("拦截"))
                                {
                                    taskBean.replyCustomer = false;
                                }
                                //handleReturnChangeAddr(wechatBean);
                                //writeStaticBarcodeEx(wechatBean.content);
                            }

                        }

                    }
                }
                

                
                else if(isCheckTask(wechatBean))
                {
                    taskBean.taskType = "审单";
                }

                else if (isQuestionTask(wechatBean))
                {
                    taskBean.taskType = "疑问";
                }

                else if (isThankTask(wechatBean))
                {
                    taskBean.taskType = "感谢";
                }
                


            }
            catch(Exception ex)
            {

            }
        }

        private bool isCustomTask(WechatMsgBean wechatBean)
        {
            bool res = false;
            try
            {
                if(wechatBean.content.Contains("缺图")&& wechatBean.content.Contains("客服反审"))
                {
                    res = true;
                }

            }
            catch(Exception ex)
            {

            }
            return res;
        }

        public Hashtable getTaskBeanSplit(WechatMsgBean wechatBean)
        {
            Hashtable htRes = new Hashtable();
            htRes["lanshou"] = "";
            htRes["gendan"] = "";
            try
            {
                StringBuilder sbLanshou = new StringBuilder();
                StringBuilder sbGendan = new StringBuilder();
                String content = wechatBean.content;
                string[] arr = content.Split('\n');
                StringBuilder sbTmp = new StringBuilder();

                int lineCount = 0;
                bool isLastLanshou = false;
                foreach(string line in arr)
                {
                    lineCount++;
                    sbTmp.AppendLine(line);
                    WechatMsgBean wechatTmp = new WechatMsgBean();
                    wechatTmp.content = line.ToString();

                    //if (isLanshouTask(wechatTmp, new TaskBean())|| isLanShouOrTransfer(wechatTmp))
                    if (isLanshouTask(wechatTmp, new TaskBean()))
                    {
                        //if(lineCount>1)
                        {
                            isLastLanshou = true;
                            htRes["lanshou"] = htRes["lanshou"] + sbTmp.ToString() + " ";
                            sbTmp.Clear();
                            lineCount = 0;
                        }
                                               
                    }

                    if (isGenDanTask(wechatTmp, new TaskBean())|| isInCommand(wechatTmp.content))
                    {
                        //if (lineCount > 1)
                        {
                            isLastLanshou = false;
                            htRes["gendan"] = htRes["gendan"] + sbTmp.ToString() + " ";
                            sbTmp.Clear();
                            lineCount = 0;
                        }
                    }

                }
                if(sbTmp.ToString().Length>1)
                {
                    if(isLastLanshou)
                    {
                        htRes["lanshou"] = htRes["lanshou"] + sbTmp.ToString() + " ";
                    }
                    else
                    {
                        htRes["gendan"] = htRes["gendan"] + sbTmp.ToString() + " ";
                    }
                }
            }
            catch(Exception ex)
            {

            }
            return htRes;
                
        }


        public void handleReturnChangeAddr(WechatMsgBean wechatBean)
        {
            string ori_addr = wechatBean.content;
            string replaceWord = "";
            if(ori_addr.Contains("拦截退回"))
            {
                replaceWord = "拦截退回";
            }
            else if(ori_addr.Contains("拦截"))
            {
                replaceWord = "拦截";
            }
            else if (ori_addr.Contains("撤件"))
            {
                replaceWord = "撤件";
            }
            else if (ori_addr.Contains("退回"))
            {
                replaceWord = "退回";
            }
            else if (ori_addr.Contains("截回"))
            {
                replaceWord = "截回";
            }
            else if (ori_addr.Contains("追回"))
            {
                replaceWord = "追回";
            }
            else if (ori_addr.Contains("追回"))
            {
                replaceWord = "追回";
            }
            else if (ori_addr.Contains("召回"))
            {
                replaceWord = "召回";
            }
            else if (ori_addr.Contains("拦回"))
            {
                replaceWord = "拦回";
            }

            else if (ori_addr.Contains("撤回"))
            {
                replaceWord = "撤回";
            }

            else if (ori_addr.Contains("已退款"))
            {
                replaceWord = "已退款";
            }
            else if (ori_addr.Contains("已经退款"))
            {
                replaceWord = "已经退款";
            }
            else if (ori_addr.Contains("催退"))
            {
                replaceWord = "催退";
            }
            else if (ori_addr.Contains("客户拒收"))
            {
                replaceWord = "客户拒收";
            }
            /*else if (ori_addr.Contains("拒收"))
            {
                replaceWord = "拒收";
            }*/
            if (replaceWord!="")
            {
                wechatBean.content = wechatBean.content.Replace(replaceWord, " 改地址 广东省东莞市凤岗镇天堂围兴业路105号，招财喵，13433698854");
                wechatBean.content = wechatBean.content.Replace("拦截退回", "");
                wechatBean.content = wechatBean.content.Replace("拦截", "");
                wechatBean.content = wechatBean.content.Replace("撤件", "");
                wechatBean.content = wechatBean.content.Replace("退回", "");
                wechatBean.content = wechatBean.content.Replace("截回", "");
                wechatBean.content = wechatBean.content.Replace("已退款", "");
                wechatBean.content = wechatBean.content.Replace("已经退款", "");
                wechatBean.content = wechatBean.content.Replace("催退", "");
                wechatBean.content = wechatBean.content.Replace("客户拒收", "");         

            }
           





        }

        private bool isQuestionTask(WechatMsgBean wechatBean)
        {
            bool res = false;
            try
            {
                wechatBean.content = wechatBean.content.Replace("？", "?");


                if (FrameDecoderManager.Instance.htForbiddenDeliverUsers.ContainsKey(wechatBean.from))
                {
                    return res;
                }

                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htCommandQuestion)
                {
                    string command = de.Key.ToString();
                    if (wechatBean.content.Contains(command))
                    {
                        res = true;
                    }
                }



            }
            catch (Exception ex)
            {

            }
            return res;
        }

        public string getLeftMessage(string content,ArrayList arListFirst, ArrayList arListSecond, ArrayList arListThird)
        {
            string res = content;
            try
            {
                foreach(string line in arListFirst)
                {
                    res = res.Replace(line, "");
                }

                foreach (string line in arListSecond)
                {
                    res = res.Replace(line+"\n", "");
                    res = res.Replace(line, "");
                }
                foreach (string line in arListThird)
                {
                    res = res.Replace(line + "\n", "");
                    res = res.Replace(line, "");
                }
            }
            catch(Exception ex)
            {

            }
            return res;

        }


        public string getLeftMessageWithYto(string content, ArrayList arListFirst, ArrayList arListSecond, ArrayList arListThird, ArrayList arListFourth)
        {
            string res = content;
            try
            {
                foreach (string line in arListFirst)
                {
                    res = res.Replace(line, "");
                }

                foreach (string line in arListSecond)
                {
                    res = res.Replace(line + "\n", "");
                    res = res.Replace(line, "");
                }
                foreach (string line in arListThird)
                {
                    res = res.Replace(line + "\n", "");
                    res = res.Replace(line, "");
                }

                foreach (string line in arListFourth)
                {
                    res = res.Replace(line + "\n", "");
                    res = res.Replace(line, "");
                }
            }
            catch (Exception ex)
            {

            }
            return res;

        }

        public bool isContainMoreCustomers(string content,ArrayList arListJT,ArrayList arListSto,ArrayList arListZto, ArrayList arListEms, ArrayList arListYT, Hashtable htCustomer,out bool isContainDouyin)
        {
            bool res = false;
            Hashtable htcus = new Hashtable();
            isContainDouyin = false;
            try
            {
                isContainDouyin = false;
                string storegexStr = StoParams.Instance.storegexStr;
                string jtRegexStr = "^(JT)[0-9]{13}$|^(55)[0-9]{13}$";

                string ytRegexStr = "^(YT)[0-9]{13}$";

                string ztoRegexStr = StoParams.Instance.ztoRegexStr;
                string emsRegexStr = "^(9)[0-9]{12}$";
                Regex emsRegex = new Regex(emsRegexStr);
                Regex stoRegex = new Regex(storegexStr);
                Regex jtRegex = new Regex(jtRegexStr);
                Regex ztoRegex = new Regex(ztoRegexStr);

                Regex ytRegex = new Regex(ytRegexStr);

                //string[] arr = content.Split('\n');
                ArrayList arr = getContinueParcelNumber(content);
                foreach (string strLine in arr)
                {

                    //string[] tmpArr = strLine.Split(' ');
                    ArrayList tmpArr = getContinueParcelNumber(strLine);
                    foreach (string val in tmpArr)
                    {
                        string valN = val;
                        string curV = val;

                        
                        if (isContainChinese(val,out valN))
                        {
                            curV = valN;
                        }
                        if (curV.Length>5)
                        {
                            string newV = curV;
                            if(newV.Length>15&& newV.Length<30)
                            {
                                newV = newV.Substring(0, 15);
                            }
                            if (stoRegex.IsMatch(newV))
                            {
                                arListSto.Add(curV);
                                htcus["sto"] = "";
                                htCustomer["STO"] = "";
                                if(newV.StartsWith("7763"))
                                {
                                    isContainDouyin = true;
                                }
                            }
                            
                        }
                        if (curV.Length > 5 )
                        {
                            string newV = curV;
                            if (newV.Length > 15 && newV.Length < 30)
                            {
                                newV = newV.Substring(0, 15);
                            }
                            if (jtRegex.IsMatch(newV))
                            {
                                arListJT.Add(curV);
                                htcus["jt"] = "";
                                htCustomer["JT"] = "";
                                if (newV.StartsWith("JT20"))
                                {
                                    isContainDouyin = true;
                                }
                            }
                           
                        }

                        if (curV.Length > 5)
                        {
                            string newV = curV;
                            if (newV.Length > 15 && newV.Length < 30)
                            {
                                newV = newV.Substring(0, 15);
                            }
                            if (ytRegex.IsMatch(newV))
                            {
                                arListYT.Add(curV);
                                htcus["yt"] = "";
                                htCustomer["YT"] = "";
                                
                            }

                        }
                        if (curV.Length > 5 )
                        {
                            string newV = curV;
                            if (newV.Length > 14 && newV.Length < 28)
                            {
                                newV = newV.Substring(0, 14);
                            }
                            if(ztoRegex.IsMatch(newV))
                            {
                                arListZto.Add(curV);
                                htcus["zto"] = "";
                                htCustomer["ZTO"] = "";
                                if (newV.StartsWith("757"))
                                {
                                    isContainDouyin = true;
                                }
                            }

                            
                        }

                        if (curV.Length > 5)
                        {
                            string newV = curV;
                            if (newV.Length > 15 && newV.Length < 30)
                            {
                                newV = newV.Substring(0, 13);
                            }
                            if (emsRegex.IsMatch(newV))
                            {
                                if(!arListEms.Contains(newV))
                                {
                                    arListEms.Add(newV);
                                }
                               
                                htcus["ems"] = "";
                                htCustomer["EMS"] = "";
                            }
                            else
                            {
                                if (newV.Length == 13 && newV.StartsWith("1") && MathUtility.ImpIsNum(newV))
                                {
                                    if (!arListEms.Contains(newV))
                                    {
                                        arListEms.Add(newV);
                                    }
                                    htcus["ems"] = "";
                                    htCustomer["EMS"] = "";
                                }
                            }

                        }

                    }
                }
                if(htcus.Count>1)
                {
                    res = true;
                }

            }
            catch(Exception ex)
            {

            }
            return res;
        }


        public int getChineseIndex(string text)
        {
            int res = -1;
            string sub = "";
            bool containJT = false;
            try
            {
                

                char[] c = text.ToCharArray();
                for (int i = 0; i < text.Length; i++)
                {
                    if ((int)c[i] > 127)
                    {
                        res = i;
                        break;

                    }
                    

                }
            }
            catch (Exception ex)
            {

            }

            
            return res;
        }


        public bool isContainChinese(string text,out string resMsg)
        {
            bool res = false;
            resMsg = text;
            string sub = "";
            bool containJT = false;
            try
            {
                if(text.Contains("JT"))
                {
                    text = text.Substring(text.IndexOf("JT") + 2);
                    containJT = true;
                }
                
                char[] c = text.ToCharArray();
                for (int i = 0; i < text.Length; i++)
                {
                    if ((int)c[i] > 127)
                    {
                        res = true;
                        if(sub.Length>12)
                        {
                            break;
                        }
                        
                    }
                    else
                    {
                        sub = sub + c[i];
                    }
                    
                }
            }
            catch(Exception ex)
            {

            }

            resMsg= sub;
            if(containJT)
            {
                if(resMsg.Length>11)
                {
                    resMsg = "JT" + resMsg;
                }
               
            }
            return res;
        }

        public bool isLanshouTask(WechatMsgBean wechatBean,TaskBean taskBean)
        {
            bool res = false;
            try
            {
                if (FrameDecoderManager.Instance.htForbiddenDeliverUsers.ContainsKey(wechatBean.from))
                {
                    if(!isInternalUserLanshouOrTransfer(wechatBean))
                    {
                        return res;
                    }
                    
                }
                if (wechatBean.content.Contains("反审"))
                {
                    return res;
                }

                ArrayList arListJT = getInputBarcodesAndAddr(wechatBean.content, taskBean);
                if(arListJT.Count>0)
                {
                    if(isLanShouOrTransfer(wechatBean))
                    {
                        taskBean.expressCus = "JT";
                        res = true;
                        return res;
                    }                    
                }

                ArrayList arListYT = this.getYTInputBarcodesAndAddr(wechatBean.content, taskBean);
                if (arListYT.Count > 0)
                {
                    if (isLanShouOrTransfer(wechatBean))
                    {
                        taskBean.expressCus = "YT";
                        res = true;
                        return res;
                    }
                }


                if (isLanShouOrTransfer(wechatBean))
                {
                    if(isZtoParcel(wechatBean.content, taskBean))
                    {
                        taskBean.expressCus = "ZTO";
                        res = true;
                        return res;
                    }
                    else if (isStoParcel(wechatBean.content, taskBean))
                    {
                        taskBean.expressCus = "STO";
                        res = true;
                        return res;
                    }
                    else if(isEmsParcel(wechatBean.content, taskBean))
                    {
                        taskBean.expressCus = "EMS";
                        res = true;
                        return res;
                    }
                }



            }
            catch (Exception ex)
            {

            }
            return res;
        }


        public void removeRetryMsg(WechatMsgBean wechatBean, TaskBean taskBean)
        {
            try
            {
                /*if (!FrameDecoderManager.Instance.htLanshopuRooms.ContainsKey(wechatBean.roomid)
                    && !FrameDecoderManager.Instance.htGendanRooms.ContainsKey(wechatBean.roomid))
                {
                    return;
                }*/
                string msg = wechatBean.content;
                string removeKey = "";
                bool findRoom = false;
                StringBuilder sbT = new StringBuilder();
                StringBuilder sbRooms = new StringBuilder();
                foreach(DictionaryEntry de in FrameDecoderManager.Instance.htRetryMsg)
                {
                    WechatMsgBean newWechatBean = (WechatMsgBean)de.Value;
                    if(newWechatBean.roomid== wechatBean.roomid)
                    {
                        findRoom = true;
                        if (newWechatBean.content== wechatBean.content)
                        {
                            //sbT.AppendLine("匹配数据成功：" + newWechatBean.content);
                            removeKey = de.Key.ToString();
                        }
                        else
                        {
                            sbT.AppendLine(newWechatBean.content);
                        }
                    }
                    else
                    {
                        sbRooms.Append(newWechatBean.roomid + ",");
                    }
                }

                if (findRoom)
                {
                    //LogHelper.Instance.writeLog(sbT.ToString());
                }
                else
                {
                    //LogHelper.Instance.writeLog("未找到roomid，对列roomid="+ sbRooms.ToString()+" 当前room="+ wechatBean.roomid);
                }
                

                StringBuilder sb = new StringBuilder();
                if(FrameDecoderManager.Instance.htRetryMsg.ContainsKey(removeKey)&& removeKey.Length>1)
                {
                    sb.AppendLine("收到转发信息：" + msg);
                    FrameDecoderManager.Instance.htRetryMsg.Remove(removeKey);
                   
                }
                if(sb.ToString().Length>1)
                {
                    sb.AppendLine("重试对列个数：" + FrameDecoderManager.Instance.htRetryMsg.Count.ToString());
                    LogHelper.Instance.writeLog(sb.ToString());
                }
                

            }
            catch(Exception ex)
            {
                LogHelper.Instance.writeLog("removeRetryMsg ex:"+ex.ToString());
            }
        }


        public bool isGenDanTask(WechatMsgBean wechatBean, TaskBean taskBean)
        {
            bool res = false;
            try
            {
                if (wechatBean.content.Contains("反审"))
                {
                    return res;
                }
                if(FrameDecoderManager.Instance.htLanshopuRooms.ContainsKey(wechatBean.roomid)
                    || FrameDecoderManager.Instance.htGendanRooms.ContainsKey(wechatBean.roomid))
                {
                    return res;
                }

                if(FrameDecoderManager.Instance.htForbiddenDeliverUsers.ContainsKey(wechatBean.from))
                {
                    if(!isInternalUserGendanTask(wechatBean))
                    {
                        return res;
                    }                      
                   
                }

                ArrayList arListJT = getInputBarcodesAndAddr(wechatBean.content, taskBean);
                if (arListJT.Count > 0)
                {
                    /*if(isCuiParcel(wechatBean.content)
                        || isCancelOrder(wechatBean.content)
                          || isInterCept(wechatBean.content)
                            || isCheckWeight(wechatBean.content)
                              || isCancelChangeAddr(wechatBean.content)
                             || isCancelInter(wechatBean.content)
                              || isChangeNumber(wechatBean.content)
                               || isQiasnshouWeiDao(wechatBean.content)
                        )*/
                    if(isInCommand(wechatBean.content))
                    {
                        taskBean.expressCus = "JT";
                        res = true;
                        return res;
                    }
                    
                }


                ArrayList arListYT = this.getYTInputBarcodesAndAddr(wechatBean.content,taskBean);
                if (arListYT.Count > 0)
                {
                    /*if(isCuiParcel(wechatBean.content)
                        || isCancelOrder(wechatBean.content)
                          || isInterCept(wechatBean.content)
                            || isCheckWeight(wechatBean.content)
                              || isCancelChangeAddr(wechatBean.content)
                             || isCancelInter(wechatBean.content)
                              || isChangeNumber(wechatBean.content)
                               || isQiasnshouWeiDao(wechatBean.content)
                        )*/
                    if (isInCommand(wechatBean.content))
                    {
                        taskBean.expressCus = "YT";
                        res = true;
                        return res;
                    }

                }

                if (isZtoParcel(wechatBean.content, taskBean))
                {
                    /*if (isCuiParcel(wechatBean.content)
                        || isCancelOrder(wechatBean.content)
                          || isInterCept(wechatBean.content)
                            || isCheckWeight(wechatBean.content)
                              || isCancelChangeAddr(wechatBean.content)
                             || isCancelInter(wechatBean.content)
                              || isChangeNumber(wechatBean.content)
                               || isQiasnshouWeiDao(wechatBean.content)
                        )*/
                    if (isInCommand(wechatBean.content))
                    {
                        taskBean.expressCus = "ZTO";
                        res = true;
                        return res;
                    }
                    
                }
                else if (isStoParcel(wechatBean.content, taskBean))
                {
                    /*if (isCuiParcel(wechatBean.content)
                        || isCancelOrder(wechatBean.content)
                          || isInterCept(wechatBean.content)
                            || isCheckWeight(wechatBean.content)
                              || isCancelChangeAddr(wechatBean.content)
                             || isCancelInter(wechatBean.content)
                              || isChangeNumber(wechatBean.content)
                               || isQiasnshouWeiDao(wechatBean.content)
                        )*/
                    if (isInCommand(wechatBean.content))
                    {
                        taskBean.expressCus = "STO";
                        res = true;
                        return res;
                    }
                    
                }

                else if (isEmsParcel(wechatBean.content, taskBean))
                {
                    /*if (isCuiParcel(wechatBean.content)
                        || isCancelOrder(wechatBean.content)
                          || isInterCept(wechatBean.content)
                            || isCheckWeight(wechatBean.content)
                              || isCancelChangeAddr(wechatBean.content)
                             || isCancelInter(wechatBean.content)
                              || isChangeNumber(wechatBean.content)
                               || isQiasnshouWeiDao(wechatBean.content)
                        )*/
                    if (isInCommand(wechatBean.content))
                    {
                        taskBean.expressCus = "EMS";
                        res = true;
                        return res;
                    }

                }

            }
            catch (Exception ex)
            {

            }
            return res;
        }


        public bool isInCommand(string content)
        {
            bool res = false;
            try
            {
                if(content.Contains("揽收"))
                {
                    return res;
                }
                foreach(DictionaryEntry de in FrameDecoderManager.Instance.htCommandGendan)
                {
                    if(de.Key.ToString().Length>1&& content.Contains(de.Key.ToString()))
                    {
                        res = true;
                        break;
                    }
                }
            }
            catch(Exception ex)
            {

            }
            return res;
        }

        public bool isLanShouOrTransfer(WechatMsgBean wechatBean)
        {
            bool res = false;
            try
            {
                if(isChangeAddr(wechatBean.content,""))
                {
                    return res;
                }

                if(wechatBean.content.Contains("揽收")
                    || wechatBean.content.Contains("中转") 
                    || wechatBean.content.Contains("发往")
                     || wechatBean.content.Contains("到达")
                      || wechatBean.content.Contains("二段")
                      || wechatBean.content.Contains("三段")
                      || wechatBean.content.Contains("揽件")
                      || (wechatBean.content.Contains("发运")&& wechatBean.content.Contains("超时"))
                       || wechatBean.content.Contains("做一下物流")
                        || wechatBean.content.Contains("二次物流")
                         || wechatBean.content.Contains("做物流")
 
                    )
                {
                    res = true;
                }

            }
            catch(Exception ex)
            {

            }
            return res;
        }

        public void initInternalUserWord()
        {
            StoParams.Instance.htInternalUserLanshouWord["揽收"] = "";
            StoParams.Instance.htInternalUserLanshouWord["中转"] = "";
            StoParams.Instance.htInternalUserLanshouWord["发往"] = "";
            StoParams.Instance.htInternalUserLanshouWord["到达"] = "";
            StoParams.Instance.htInternalUserLanshouWord["做发往"] = "";
            StoParams.Instance.htInternalUserLanshouWord["做到达"] = "";

            StoParams.Instance.htInternalUserGendanWord["拦截"] = "";
            StoParams.Instance.htInternalUserGendanWord["改地址"] = "";
            StoParams.Instance.htInternalUserGendanWord["改号码"] = "";
            StoParams.Instance.htInternalUserGendanWord["催件"] = "";
            StoParams.Instance.htInternalUserGendanWord["核实物流"] = "";
        }


        public bool isInternalUserLanshouOrTransfer(WechatMsgBean wechatBean)
        {
            bool res = false;
            try
            {
                string chineseStr = UtilityHelp.Instance.GetChineseCharacters(wechatBean.content);
                string singleContent = wechatBean.content.Replace(chineseStr, "");
                singleContent = singleContent.Trim();
                if (StoParams.Instance.htInternalUserLanshouWord.ContainsKey(singleContent) && singleContent.Length>1)
                {
                    res = true;
                }

            }
            catch (Exception ex)
            {

            }
            return res;
        }


        public bool isInternalUserGendanTask(WechatMsgBean wechatBean)
        {
            bool res = false;
            try
            {
                string chineseStr = UtilityHelp.Instance.GetChineseCharacters(wechatBean.content);
                string singleContent= wechatBean.content.Replace(chineseStr, "");
                singleContent = singleContent.Trim();
                string otherGendContent = singleContent;
                TaskBean taskBean = new TaskBean();
                if (singleContent.Contains("改地址"))
                {
                    singleContent = singleContent.Substring(singleContent.LastIndexOf("改地址") + 3);
                    string[] arr = singleContent.Split('\t');
                    if(arr.Length>5)
                    {
                        return res;
                    }
                    arr = singleContent.Split('\n');
                    if (arr.Length > 5)
                    {
                        return res;
                    }

                    if(isZtoParcel(singleContent, taskBean))
                    {
                        return res;
                    }
                    if (isStoParcel(singleContent, taskBean))
                    {
                        return res;
                    }

                    //singleContent = singleContent.Substring(singleContent.IndexOf("改地址"));
                    List<string> phoneList = UtilityHelp.Instance.GetTelephoneList(singleContent, " ");
                    int contentLength = singleContent.Length;
                    if(contentLength>150)
                    {
                        return res;
                    }
                    if (phoneList.Count > 2)
                    {
                        return res;
                    }
                    if (phoneList.Count>0)
                    {
                        res = true;
                    }

                }

                if (StoParams.Instance.htInternalUserGendanWord.ContainsKey(otherGendContent) && otherGendContent.Length > 1)
                {
                    res = true;
                }

            }
            catch (Exception ex)
            {

            }
            return res;
        }



        public bool isThankTask(WechatMsgBean wechatBean)
        {
            bool res = false;
            try
            {
                if (FrameDecoderManager.Instance.htForbiddenDeliverUsers.ContainsKey(wechatBean.from))
                {
                    return res;
                }
                if (wechatBean.content.Contains("谢谢")
                    || wechatBean.content.Contains("感谢")
                     || wechatBean.content.Contains("谢了")
                      || wechatBean.content.Contains("辛苦")
                    )
                {
                    res = true;
                }
               

            }
            catch (Exception ex)
            {

            }
            return res;
        }



        public bool isCodingTask(WechatMsgBean wechatBean)
        {
            bool res = false;
            try
            {
                

                if (FrameDecoderManager.Instance.htForbiddenDeliverUsers.ContainsKey(wechatBean.from))
                {
                    if ((wechatBean.content.Trim() == "核实编码") || (wechatBean.content.Trim() == "做编码"))
                    {
                        return true;
                    }

                    return res;

                }

                foreach(DictionaryEntry de in FrameDecoderManager.Instance.htCommandCoding)
                {
                    string command = de.Key.ToString();
                    if(wechatBean.content.Contains(command))
                    {
                        res = true;
                    }
                }      
                if (wechatBean.content.StartsWith("https://")&& wechatBean.content.Contains("="))
                {
                    res = true;
                }
                if(wechatBean.file.ToString().Contains("编码")|| wechatBean.file.ToString().Contains("商品映射"))
                {
                    res = true;
                }
                
            }
            catch(Exception ex)
            {

            }
            return res;
        }


        public bool isChangeCodingTask(WechatMsgBean wechatBean)
        {
            bool res = false;
            try
            {
                if (FrameDecoderManager.Instance.htForbiddenDeliverUsers.ContainsKey(wechatBean.from))
                {
                    return res;
                }

                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htCommandChangeCoding)
                {
                    string command = de.Key.ToString();
                    if (wechatBean.content.Contains(command))
                    {
                        res = true;
                    }
                }
               

            }
            catch (Exception ex)
            {

            }
            return res;
        }

        public bool isCheckTask(WechatMsgBean wechatBean)
        {
            bool res = false;
            try
            {
                wechatBean.content = wechatBean.content.Replace("？", "?");


                if (FrameDecoderManager.Instance.htForbiddenDeliverUsers.ContainsKey(wechatBean.from))
                {
                    return res;
                }

                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htCommandCheck)
                {
                    string command = de.Key.ToString();
                    if (wechatBean.content.Contains(command))
                    {
                        res = true;
                    }
                }

             
        
            }
            catch (Exception ex)
            {

            }
            return res;
        }



        public bool isDrawingTask(WechatMsgBean wechatBean)
        {
            bool res = false;
            try
            {
                if (FrameDecoderManager.Instance.htForbiddenDeliverUsers.ContainsKey(wechatBean.from))
                {

                    if (wechatBean.content.Trim()=="核实图库"|| wechatBean.content.Trim() == "存图")
                    {
                        return true;
                    }
                    return res;

                    
                    
                }
                /*if (wechatBean.content.Contains("存图") 
                    || wechatBean.content.Contains("存个图")
                    || wechatBean.content.Contains("换图")
                    || wechatBean.content.Contains("错图")

                     || wechatBean.content.Contains("替换图")
                    || wechatBean.content.Contains("核实图库"))
                {
                    res = true;
                }*/

                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htCommandDraw)
                {
                    string command = de.Key.ToString();
                    if (wechatBean.content.Contains(command))
                    {
                        res = true;
                    }
                }

                if (wechatBean.file!="")
                {
                    if(wechatBean.file.EndsWith("zip")|| wechatBean.file.EndsWith("rar") || wechatBean.file.EndsWith("png") || wechatBean.file.EndsWith("PNG")
                        || wechatBean.file.EndsWith("7z") || wechatBean.file.EndsWith("psd") || wechatBean.file.EndsWith("PSD") || wechatBean.file.EndsWith("ttf"))
                    {
                        if(!wechatBean.file.Contains("商品映射"))
                        {
                            res = true;
                        }
                       
                    }
                    if (wechatBean.file.EndsWith("tif")|| wechatBean.file.EndsWith("tiff"))
                    {
                        res = true;
                    }
                }

                


            }
            catch (Exception ex)
            {

            }
            return res;
        }


        public string getResponseMsg(string content,string task)
        {
            string res = "已通知快递处理哦";
            try
            {
                if(task=="揽收")
                {
                    if(content.Contains("揽收"))
                    {
                        res = "揽收已通知~";
                        //2025-01-04
                        StringBuilder sbRes = new StringBuilder();
                        sbRes.AppendLine("揽收已通知~");
                        //sbRes.AppendLine("(因春节快递网点考核，政策多变，预揽收不一定成功。我们会尽力催，多次无果则无法揽收，望谅。)");
                        res = sbRes.ToString().Replace("\r\n", "\n");
                    }
                    else if (content.Contains("中转"))
                    {
                        res = "中转已通知处理";
                        //2025-01-04
                        StringBuilder sbRes = new StringBuilder();
                        sbRes.AppendLine("中转已通知~");
                        //sbRes.AppendLine("(因快递网点政策调整，目前圆通、申通无法预中转哦)");
                        res = sbRes.ToString().Replace("\r\n", "\n");
                    }
                    else if (content.Contains("发往"))
                    {
                        res = "发往已通知处理";
                    }
                    else if (content.Contains("到达"))
                    {
                        res = "到达已通知处理";
                    }
                    else if (content.Contains("二段"))
                    {
                        res = "二段已通知处理";
                    }
                    else if (content.Contains("三段"))
                    {
                        res = "三段已通知处理";
                    }
                }
            }
            catch(Exception ex)
            {

            }
            return res;

        }




        internal void resetCommadnGendan(WechatMsgBean wechatBean,out string msg)
        {
            msg = "成功";
            try
            {
               
                string content = wechatBean.content.Replace("设置快递指令", "").Replace("，",",");
                if(!content.Contains(","))
                {
                    msg = "失败,指令格式不正确，应该以 ,分割";
                    return;
                }
                content = content.Replace("：", "");
                content = content.Replace(":", "");
                string[] arr = content.Split(',');
                ArrayList arListCommand = new ArrayList();
                foreach(string val in arr)
                {
                    if(val.Trim().Length>1)
                    {
                        FrameDecoderManager.Instance.htCommandGendan[val.Trim()] = val;
                        arListCommand.Add(val);
                    }
                    
                }


                this.setCommandGendan();
            }
            catch(Exception x)
            {

            }
        }

        public  string GetChineseCharacters(string input)
        {
            return Regex.Replace(input, @"[\u4e00-\u9fa5]", "");
        }


        internal void removeCommadnGendan(WechatMsgBean wechatBean, out string msg)
        {
            msg = "成功";
            try
            {

                string content = wechatBean.content.Replace("取消快递指令", "").Replace("，", ",");
                content = content.Replace("：", "");
                content = content.Replace(":", "");

                string[] arr = content.Split(',');
                ArrayList arListCommand = new ArrayList();
                foreach (string val in arr)
                {
                   if(val.Trim().Length>1)
                   {
                        arListCommand.Add(val);
                        if (FrameDecoderManager.Instance.htCommandGendan.ContainsKey(val.Trim()))
                        {
                            FrameDecoderManager.Instance.htCommandGendan.Remove(val.Trim());
                        }
                    }
                    
                }


                this.setCommandGendan();
            }
            catch (Exception x)
            {

            }
        }


        internal void removeCommadDraw(WechatMsgBean wechatBean, out string msg)
        {
            msg = "成功";
            try
            {

                string content = wechatBean.content.Replace("取消艾特美工指令", "").Replace("，", ",");
                content = content.Replace("：", "");
                content = content.Replace(":", "");

                string[] arr = content.Split(',');
                ArrayList arListCommand = new ArrayList();
                foreach (string val in arr)
                {
                    if (val.Trim().Length > 1)
                    {
                        arListCommand.Add(val);
                        if (FrameDecoderManager.Instance.htCommandDraw.ContainsKey(val.Trim()))
                        {
                            FrameDecoderManager.Instance.htCommandDraw.Remove(val.Trim());
                        }
                    }

                }


                this.setCommandDraw();
            }
            catch (Exception x)
            {

            }
        }


        internal void removeCommadCoding(WechatMsgBean wechatBean, out string msg)
        {
            msg = "成功";
            try
            {

                string content = wechatBean.content.Replace("取消做编码指令", "").Replace("，", ",");
                content = content.Replace("：", "");
                content = content.Replace(":", "");

                string[] arr = content.Split(',');
                ArrayList arListCommand = new ArrayList();
                foreach (string val in arr)
                {
                    if (val.Trim().Length > 1)
                    {
                        arListCommand.Add(val);
                        if (FrameDecoderManager.Instance.htCommandCoding.ContainsKey(val.Trim()))
                        {
                            FrameDecoderManager.Instance.htCommandCoding.Remove(val.Trim());
                        }
                    }

                }


                this.setCommandCoding();
            }
            catch (Exception x)
            {

            }
        }


        internal void removeChangeCommadCoding(WechatMsgBean wechatBean, out string msg)
        {
            msg = "成功";
            try
            {

                string content = wechatBean.content.Replace("取消改编码指令", "").Replace("，", ",");
                content = content.Replace("：", "");
                content = content.Replace(":", "");

                string[] arr = content.Split(',');
                ArrayList arListCommand = new ArrayList();
                foreach (string val in arr)
                {
                    if (val.Trim().Length > 1)
                    {
                        arListCommand.Add(val);
                        if (FrameDecoderManager.Instance.htCommandChangeCoding.ContainsKey(val.Trim()))
                        {
                            FrameDecoderManager.Instance.htCommandChangeCoding.Remove(val.Trim());
                        }
                    }

                }


                this.setChangeCommandCoding();
            }
            catch (Exception x)
            {

            }
        }


        public void setCommandGendan()
        {
            try
            {
                Hashtable htWechatMap = new Hashtable();
                StringBuilder sb = new StringBuilder();
                ArrayList arListAllLines = new ArrayList();

                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htCommandGendan)
                {
                    string commadn = de.Key.ToString();

                    arListAllLines.Add(commadn);

                }
                logHelp.LogHelper.Instance.writeConfig(StoParams.Instance.allGendanCommandTxtPath, arListAllLines);

            }
            catch (Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog(" setCommandGendan ex" + ex.ToString());
            }
        }



        public void setCommandDraw()
        {
            try
            {
                Hashtable htWechatMap = new Hashtable();
                StringBuilder sb = new StringBuilder();
                ArrayList arListAllLines = new ArrayList();

                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htCommandDraw)
                {
                    string commadn = de.Key.ToString();

                    arListAllLines.Add(commadn);

                }
                logHelp.LogHelper.Instance.writeConfig(StoParams.Instance.allDrawCommandTxtPath, arListAllLines);

            }
            catch (Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog(" setCommandDraw ex" + ex.ToString());
            }
        }


        public void setCommandCoding()
        {
            try
            {
                Hashtable htWechatMap = new Hashtable();
                StringBuilder sb = new StringBuilder();
                ArrayList arListAllLines = new ArrayList();

                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htCommandCoding)
                {
                    string commadn = de.Key.ToString();

                    arListAllLines.Add(commadn);

                }
                logHelp.LogHelper.Instance.writeConfig(StoParams.Instance.allCodingCommandTxtPath, arListAllLines);

            }
            catch (Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog(" setCommandCoding ex" + ex.ToString());
            }
        }


        public void setChangeCommandCoding()
        {
            try
            {
                Hashtable htWechatMap = new Hashtable();
                StringBuilder sb = new StringBuilder();
                ArrayList arListAllLines = new ArrayList();

                foreach (DictionaryEntry de in FrameDecoderManager.Instance.htCommandChangeCoding)
                {
                    string commadn = de.Key.ToString();

                    arListAllLines.Add(commadn);

                }
                logHelp.LogHelper.Instance.writeConfig(StoParams.Instance.allChangeCodingCommandTxtPath, arListAllLines);

            }
            catch (Exception ex)
            {
                logHelp.LogHelper.Instance.writeLog(" setChangeCommandCoding ex" + ex.ToString());
            }
        }



        public void writeStaticBarcodeEx(string content)
        {
            try
            {
                string dir = System.Environment.CurrentDirectory + "\\static";
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                //判断文件是否存在，不存在则创建的存在
                string sPath = dir;
                string date = System.DateTime.Now.ToString("yyyy-MM-dd");
                sPath = Path.Combine(dir, date + "-static.txt");
                //System.Windows.Forms.MessageBox.Show("sPath:" + sPath);
                if (!File.Exists(sPath))
                {
                    FileStream fs = File.Create(sPath);//创建文件
                    fs.Close();
                }
                StreamWriter swb = new StreamWriter(sPath, true);
          
                swb.WriteLine(content.ToString());
                swb.Close();
            }
            catch (Exception ex)
            {
                //System.Windows.Forms.MessageBox.Show("writeLog error:"+ ex.ToString());
            }

        }


        public bool isNotTask(string content)
        {
            bool res = false;
            if(content.Contains("请提供完整的地址信息")&& content.Contains("改地址"))
            {
                res = true;
            }
            if (content.Trim().StartsWith("\""))
            {
                res = true;
            }
            return res;
        }










    }
}
